Global macros can be executed in all Corel Presentations documents. Global macros are stored in a special file called Presentations11.GMS. All objects that are used by a Global macro are also stored in the Presentations11.GMS. For example, if a macro uses a form, then the form is stored in the Presentations11.GMS.
2. Double-click on Global Macros in the Project view.
3. Click Insert, User Form.
4. Change the form so that it resembles the following diagram:
5. Change the name of the TextBox control to NameBox as illustrated in the following list:
Command Button - CommandButton1
TextBox - NameBox
You can change all of the control's attributes, including the name of the control, in the Property dialog box located in the Visual Basic Editor.
6. Double-click the CommandButton1 control to create a new method for the UserForm1 class, then type the following lines of code in the CommandButton1_Click method:
Private Sub CommandButton1_Click()
Dim myname, Msg As String
myname = NameBox
Msg = "Hello " & myname
MsgBox Msg
End
End Sub
This code responds to the event that occurs when the command button is clicked.
7. Double-click the Presentations Objects folder that appears under the Global Macros project in the Project view.
8. Double-click ThisSlideShow that appears under the Global Macros project, then type the following lines of code in the Editor window:
Public Sub ShowForm()
End Sub
This code will add a new method to the ThisSlideShow class. If you declare ShowForm as a Private method, you will not be able to run it from Corel Presentations.
9. Type the following line of code in the ShowForm method:
Public Sub ShowForm()
UserForm1.Show
End Sub
Note
The name of this macro is ShowForm. The name of the form is UserForm1, which is the default name. UserForm1, along with this macro would be stored in Presentations11.GMS.
Corel Presentations VBA Events
Visual Basic for Applications (VBA) is an event-driven programming language. Most of the code you create is written to respond to an event. An event is an action that is recognized by VBA; for example, clicking a button or choosing an option from a list box. Unlike traditional procedural programming, in which the program starts at line 1 and executes line by line, event-driven programming executes code in response to events.
Corel Presentations slideshow events can be broken down into two categories: Global and Project events. A Global event is an event which is recognized by all Corel Presentations slide shows. Suppose you create a VBA macro in the AfterOpen Event. This macro would be valid for any Corel Presentations slideshow. In contrast to Global events there are Project events. A Project event is recognized only by the local slideshow.
All events in Corel Presentations are code placeholders. It is up to you to code the response. All events are called in response to a specific action. When an action occurs, the appropriate event will be called and the code located within the event is executed. You can create simple or complex events. You can code a single line that displays a Message Box or write an entire procedure that interacts with a database.
All Global events are members of the GlobalMacros class. The name of the object is the same as the class. All Project events are members of the Document class. The name of the object is the same as the class.
Global Events
BeforeSwitchDocument()
AfterSwitchDocument()
BeforeNew()
AfterNew()
BeforeOpen()
AfterOpen()
BeforePrint()
AfterPrint()
BeforeClose()
BeforeSave()
AfterSave()
AfterStartup()
Document Events
BeforeOpen()
AfterOpen()
BeforePrint()
AfterPrint()
BeforeSave()
AfterSave()
GlobalMacros.BeforeClose()
Syntax
Private Sub GlobalMacros_BeforeClose()
Description
This event is called before you close the slideshow.
Example
In the following code fragment, a MessageBox informs the user that the slideshow will be closed.
Private Sub GlobalMacros_BeforeClose()
'******* Declare all variables
Dim Msg as String
Msg = "You are about to close Presentations?" ' Define message.
'****** Display the MessageBox
MsgBox Msg
End Sub
GlobalMacros.BeforeSwitchDocument()
Syntax
Private Sub GlobalMacros_BeforeSwitchDocument()
Description
This event is called when you switch slideshows. The code is executed before the new slideshow appears.
Example
In the following code fragment, a Message Box appears with the time and date. This data can be stored to a database which keeps track of file activities.
Private Sub GlobalMacros_BeforeSwitchDocument()
'*** Declare all variables
Dim myTime
Dim myDate As Date
Dim myStrTime, myStrDate, Msg As String
'**** Populate the variables
myTime = Time
myDate = Date
myStrDate = Str(myDate)
myStrTime = Str(myTime)
'*** Display the MessageBox
Msg = "The date is " & myStrDate & " and the time is " & myStrTime
MsgBox Msg
End Sub
GlobalMacros.AfterSwitchDocument()
Syntax
Private Sub GlobalMacros_AfterSwitchDocument()
Description
This event is called after you have switched to a new slideshow. In contrast to BeforeSwitchDocument(), this event is executed after the new slideshow appears.
Example
In the following code fragment, a Message Box appears with the time and date. This data can be stored to a database which keeps track of file activities.
Private Sub GlobalMacros_AfterSwitchDocument()
'*** Declare all variables
Dim myTime
Dim myDate As Date
Dim myStrTime, myStrDate, Msg As String
'**** Populate the variables
myTime = Time
myDate = Date
myStrDate = Str(myDate)
myStrTime = Str(myTime)
'*** Display the MessageBox
Msg = "The date is " & myStrDate & " and the time is " & myStrTime
MsgBox Msg
End Sub
GlobalMacros.BeforeNew()
Description
This event is called when you select a new slideshow; however, this code is executed before the new slideshow appears.
Example
In the following example, a form which displays an image appears. The important concept to note is that the form will be appear before the new slideshow appears.
Private Sub GlobalMacros_BeforeNew()
FallsForm.Show
End Sub
GlobalMacros.AfterNew()
Syntax
Private Sub GlobalMacros_AfterNew()
Description
This event is called when you select a new slideshow; however, this code is executed after the new slideshow appears.
Example
In the following example, a textbox is inserted into the first slide.
Private Sub Document_AfterOpen()
With PerfectScript
.AddTextBox 3000,3000,10000,4000
.KeyType "Added by AfterOpen event"
.TextEditExit
End With
End Sub
GlobalMacros.BeforeOpen()
Syntax
Private Sub GlobalMacros_BeforeOpen()
Description
This event is called when you open an existing slideshow; however, this code is executed before the slideshow appears.
Example
In the following code fragment, a form is called which displays the time at which the slideshow is opened.
Private Sub GlobalMacros_BeforeOpen()
TimeForm.Show
End Sub
GlobalMacros.AfterOpen()
Syntax
Private Sub GlobalMacros_AfterOpen()
Description
This event is called when you open an existing slideshow. This code is executed after the slideshow has been loaded internally.
Example
In the following example, a textbox is inserted into the first slide.
Private Sub GlobalMacros_AfterOpen()
With PerfectScript
.AddTextBox 3000,3000,10000,4000
.KeyType "Added by AfterOpen event"
.TextEditExit
End With
End Sub
GlobalMacros.BeforePrint()
Syntax
Private Sub GlobalMacros_BeforePrint()
Description
This event is called when you print the slideshow. The code is executed after the "Print to" dialog box is closed, but before the slideshow is sent to the printer.
GlobalMacros.AfterPrint()
Syntax
Private Sub GlobalMacros_AfterPrint()
Description
This event is called when you print the slideshow. The code is executed after the slideshow is sent to the printer.
GlobalMacros.BeforeSave()
Syntax
Private Sub GlobalMacros_BeforeSave()
Description
This event is called when you save the slideshow. This code is executed just before the slideshow is saved allowing you to customize your slideshow.
GlobalMacros.AfterSave()
Syntax
Private Sub GlobalMacros_AfterSave()
Description
This event is called after you have saved your slideshow.
Example
In the following code fragment, a Message Box appears with the time and date. This data can be stored to a database which keeps track of file activities.
Private Sub GlobalMacros_AfterSave()
'*** Declare all variables
Dim myTime
Dim myDate As Date
Dim myStrTime, myStrDate, Msg As String
'**** Populate the variables
myTime = Time
myDate = Date
myStrDate = Str(myDate)
myStrTime = Str(myTime)
'*** Display the MessageBox
Msg = "The date is " & myStrDate & " and the time is " & myStrTime
MsgBox Msg
End Sub
GlobalMacros.AfterStartup()
Syntax
Private Sub GlobalMacros_AfterStartup()
Description
This event is called when Corel Presentations starts. The code in this event is executed while the splash screen is active.
Example
In the following code fragment, a MessageBox appears asking the user if they want a textbox inserted into the new slide. If the user selects Yes, then the textbox will be inserted into the slide.
Private Sub GlobalMacros_AfterStartup()()
'******* Declare all variables
Dim Msg, Style, Title, Response
Msg = "Do you want to insert a text box?" ' Define message.
Style = vbYesNo + vbQuestion ' Define buttons.
Title = "Presentations 11.0" ' Define title.
'****** Get the Users Input
Response = MsgBox(Msg, Style, Title)
If Response = vbYes Then ' User chose Yes.
'****** Insert a chart
With PerfectScript
.AddTextBox 3000,3000,10000,4000
.KeyType "Added by AfterStartup event"
.TextEditExit
End With
Else
MsgBox ("No text box was inserted!")
End If
End Sub
Document.BeforeOpen()
Syntax
Private Sub Document_BeforeOpen()
Description
This event is called when you open a slideshow. The code in the event is executed before the slideshow appears.
Example
In the following code fragment, a Message Box appears which displays the time and date. This data can be written to a database that keeps track of file activities.
Private Sub Document_BeforeOpen()
'*** Declare all variables
Dim myTime
Dim myDate As Date
Dim myStrTime, myStrDate, Msg As String
'**** Populate the variables
myTime = Time
myDate = Date
myStrDate = Str(myDate)
myStrTime = Str(myTime)
'*** Display the Message Box
Msg = "The date is " & myStrDate & " and the time is " & myStrTime
MsgBox Msg
End Sub
Note
The Message Box will appear before the slideshow is opened. After the Message Box is closed, the slideshow will open.
Document.AfterOpen()
Syntax
Private Sub Document_AfterOpen()
Description
This code is executed after the slideshow has been loaded internally. You can customize your slideshow by writing code in this event.
Example
In the following example, a textbox is inserted into the first slide.
Private Sub Document_AfterOpen()
With PerfectScript
.AddTextBox 3000,3000,10000,4000
.KeyType "Added by AfterOpen event"
.TextEditExit
End With
End Sub
Document.AfterPrint()
Syntax
Private Sub Document_AfterPrint()
Description
This event is called after you have printed your slideshow.
Example
You can create a simple macro that informs the user that the slideshow is printed by coding a Message Box.
Private Sub Document_AfterPrint()
MsgBox ("You have just printed this slideshow")
End Sub
Document.BeforePrint()
Syntax
Private Sub Document_BeforePrint()
Description
This event is called just before the slideshow is sent to the printer. This enables you to customize your slideshow before it is printed.
Example
In the following example, a form is called which simply displays an image.
Private Sub Document_BeforePrint()
'******* Call the Form
FallsForm.Show
End Sub
Note
The FallsForm is a VB Form which contains an image control.
Document.AfterSave()
Syntax
Private Sub Document_AfterSave()
Description
This event is called after you have saved your slideshow.
Example
In the following code fragment, a Message Box appears with the time and date. This data can be stored to a database which keeps track of file activities.
Private Sub Document_AfterSave()
'*** Declare all variables
Dim myTime
Dim myDate As Date
Dim myStrTime, myStrDate, Msg As String
'**** Populate the variables
myTime = Time
myDate = Date
myStrDate = Str(myDate)
myStrTime = Str(myTime)
'*** Display the Message Box
Msg = "The date is " & myStrDate & " and the time is " & myStrTime
MsgBox Msg
End Sub
Document.BeforeSave()
Syntax
Private Sub Document_BeforeSave()
Description
This event is called just before the slideshow is saved. This gives you a chance to customize your slideshow before it is saved.
Example
In the following example, the zoom setting is changed so that all objects in the slide are playback size. This setting will last until it is changed.
Private Sub Document_BeforeSave()
PerfectScript.ZoomToSlideShowSize
End Sub
Document.BeforeClose()
Syntax
Private Sub Document_BeforeClose()
Description
This event is called when the slideshow is closed; however, this code is executed before the slideshow is actually closed.
Example
In the following code example, a Message Box will inform the user that the slideshow will close. This Message Box will appear before the slideshow is closed.
Private Sub Document_BeforeClose()
MsgBox "You are about to close this slideshow"
End Sub
Working with product commands that use a variable
You must declare a variable that you pass to a product command as a Variant.
A Boolean value is returned to myAnswer. If the directory exists, then myAnswer will be assigned the value True. If the directory does not exist, then myAnswer will be assigned False.
Corel Presentation product commands that use WordPerfect unit values
There are many product commands which require an argument to be expressed in WordPerfect units. Here is a formula to help convert from inches to WordPerfect units:
WordPerfect unit = (n*1200), where n is inches.
Product commands that use unit values:
AddArc
AddPolyCurve
AddPolyLine
AddPolyLineWithEndCaps
AddRoundedRect
AddTextBox
ChartSetCreateSize
DocumentFormSettings
DrawingSizeSettings
ObjectAreaSelect
ObjectMove
ObjectPointSelect
ObjectScale
ObjectSetLineWidth
PreferenceFormSettings
PrintDocument
SetGridSnapOptions
SetTextLineAttributes
TextKerning
Working with repeating parameters
You must create and pass an array to each product command that has repeating parameters. Refer to the following code example, which illustrates two different code techniques:
Example 1
Sub TestPolyLine()
Dim x As Variant
Dim y As Variant
x = Array (3000,8000,8000,3000)
y = Array (3500,3200,7500,7000)
With PerfectScript
.AddPolyLine OpenFrame_AddPolyLine_FillAndFrame, 4, x, y
You must use the integer values when populating an array used for repeating parameters.
Product commands with repeating parameters
To use product commands in VBA with repeating parameters, you must declare an array. Values for each repetitive parameter must be loaded into the array. After the array is populated, you have to pass the array The following list is all the product commands with repeating parameters:
Product commands with repeating parameters:
AddPolyCurve
AddPolyLine
AddPolyLineWithEndCaps
AirBrush
ChartBoxFields
PaintBrush
PaintEraser
SelectBox
SelectiveReplace
Code Example%43211>commands
VBA programming issues relating to product commands
There are several issues that must be discussed with respect to programming with product commands in the VBA environment. You can click on any of the following gray boxes for a detailed explanation:
Product commands with repeating parameters
Calling product commands outside of the intended scope