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
VBA Security
Guide to CorelDraw VBA

Event Programming

VBA can be written to run code when certain events occur, such as opening a file , change pages etc. In this example we will run a macro whenever a new page is created.

In the VBA editor in ThisDocument at the top of the code page is a heading at the left called "(General)". If you click the heading "(General)" it will show a dropdown box which has the option to select another heading "Document". Select the heading "Document". The dropdown box will show the following options in CorelDraw X5, the options maybe be different in other versions of CorelDraw.


Also some new code will appear. It may be something like this.

Private Sub Document_QueryClose(Cancel As Boolean)
End Sub

This is only a default event. Delete all this new code and select from the heading to the right of the heading "Document". Select "PageCreate". New code identical to this will appear.

Private Sub Document_PageCreate(ByVal Page As Page)

End Sub

Between the two lines of code write EXAMPLE. Now your macro EXAMPLE will run every time you create a new page in your document. Try it. Go to the CorelDraw document (remember Alt-F11) and create a new page.

What ever code is between the opening and closing of an event will be run when the event occurs and there are many events to choose from.

There are additional events that can be handled. These are accessed by creating a class module very similar to that in Microsoft Word. I will leave the method to another day but here are the additional class events.


Issued 2017_08_31