CorelDraw & VBA
Back to the Main Menu
VBA Introduction
Artistic Text
Paragraph Text
Finding & Changing Text
Master Layers
Opening Other Applications
User Interface
Event Programming
Storing User Data
Error Handling
Speeding Up CorelDraw
CQL
VBA Security
 
Guide to CorelDraw VBA


Opening Other Applications


There are 2 types of applications that support VBA.
Primary VBA applications are those in which you can write and save VBA code within their files.
Secondary VBA applications that are designed to support VBA but you cannot write or save VBA code within these applications.
Any Primary VBA application can open and manipulate another Primary or Secondary VBA application using VBA.

Primary VBA Programs that support VBA are;
           AutoCAD
           Corel Draw
           Corel PhotoPaint
           Microsoft Access
           Microsoft Excel
           Microsoft Outlook
           Microsoft PowerPoint
           Microsoft Publisher
           Microsoft Visio
           Microsoft Word


Secondary VBA Programs are;
           Adobe Acrobat
           Adobe Illustrator
           Adobe PhotoShop
           Microsoft Internet Explorer

These secondary level applications cannot run VBA themselves but can be controlled via VBA from primary applications.
There maybe other Adobe products, such as Indesign, that support VBA but I have not investigated them.

From any primary VBA application such as CorelDraw you can control Acrobat to;
            combine multiple Acrobat files into one,
            delete pages from an Acrobat file,
            count the number of pages in an Acrobat file,
            insert a page into an Acrobat file,
            move pages including reversing the page order,
            search an Acrobat file for text,
            copy text,
            crop pages,
            rotate pages,
            save or save to another pdf,
            work with bookmarks although it is it bit limited.

Adobe Acrobat it more automatically controlled by JavaScript, another computer language, but Adobe has provided Inter-Application Communication (IAC) that allows VBA to interface with JavaScript.

Early and Late Binding
If VBA opens another application, say CorelDraw opens Excel, you can explicitly direct the VBA code to the Excel application or let the code find the application itself when it runs. There are advantages and disadvantages for both methods.

If you "Early Bind", you reference the application in the Tools menu. Also your code should use the object names used by the referenced application such as WorkBook, WorkSheet, Cells etc. The advantage of early binding is that you get intellisense as you type. ie The IDE prompts you as you type by providing a drop-down list of commands and properties.

The disadvantage of Early Binding is that if the user has a different version of the application referenced, either due to an update or a new installation or you supply your CorelDraw file to someone who has a different version of the application that your code is opening your code will fail.

With "Late Binding" you do not reference the application you are opening such as Excel. Your code if written correctly will find a reference to the application itself. This is similar to having a text file with the extension ".txt". If you double click on the file it will automatically open in Notepad. But it could have open in WordPad or Word. Similarly if you have two versions of Excel on your computer and your code requires the latest version then Late Binding may or may not open the version you want.

Late Binding does not use the object names such as WorkBooks, WorkBook, WorkSheet etc but instead uses the names Objects or Object. This makes it a little more difficult to write the code especially without intellisense.

The major advantage of Late Binding is that your code will open an application without knowing the versions.

What I do is develop the code as an Early Binding version. When happy with the code I then convert it to Late Binding so it will run on other people's computers.


Microsoft Programs
Microsoft VBA programs require a standard VBA format to open them.
In the Late Binding code below replace PROGRAM with either; Access, Excel, Publisher, PowerPoint or Word.

       Dim objApplication as Object
       Set objApplication = CreateObject("PROGRAM.application")
       objApplication.Visible = True

Alternatively you can use the Early Binding code below but you must reference the Program under Tools;
       Dim appApplication as PROGRAM.Application
       Set appApplication = New PROGRAM.Application
       appApplation.Visicible = True

Microsoft Outlook can be open with either of the above codes but it crashes at .visible - True and remains invisible.
I have not studied Outlook nor have the need to overcome this problem.

If the program is already open use this Early Binding code but you must reference the Program under Tools;
       Dim appApplication As PROGRAM.Application
       Set appApplication = GetObject(, "PROGRAM.application")
       'You can instead use the next line.
       'Set appApplication = PROGRAM.Application

Alternatively you can use this Early Binding code below but you must reference the Program under Tools;
       Dim appApplication as PROGRAM.Application
       Set appApplication = New PROGRAM.Application
       appApplication.Visible = True

Corel Programs
If you are opening a Corel program from say Excel use this Early Binding code.
If the Corel application is already open use the same code.
Remember to reference the Corel application in Tools References;

       Dim appApplication As APPLICATION.Application
       Set appApplication = APPLICATION.Application
       appApplication.Visible = True

Again here APPLICATION can be either CorelDraw or PhotoPaint.


If you are opening a Corel program from say Excel use this Late Binding code.
If the Corel application is already open use the same code.

       Dim objApplication As Object
       Set objApplicatiuon = CreateObject("APPLICATION.Application")
       objApplication.Visible = True

Where APPLICATION can be CorelDraw or Corel PhotoPaint.


Issue date 2017_08_31