WordPerfect lets you create commands, such as MessageBox or GetString, that gather information for macros. You can use these types of commands, for example, to prompt the user to type in information. For information about the MessageBox command, see the PerfectScript Programming Macros Help in the PerfectScript macro command browser.
Using GetString, GetUnits, and GetNumber
You can use the GetString command to retrieve information, such as text or numbers, as text. The GetString command uses the following format:
GetString (Var;Prompt Text; Title; MaxLength)
The prompt text, title, and maximum parameter length are optional. You can use the GetUnits command if you want to provide WordPerfect with measurement information that can be used to move the cursor and set margins. If you want WordPerfect to use the information entered in a numeric expression (such as addition or subtraction), you can use the GetNumber command. Both the GetUnits and GetNumber commands are similar to the GetString command; however, they do not use maximum parameter length. The user can use any of the following abbreviations to represent units of measurement:
Unit of measurement Abbreviation
WP Units (1200 per inch) w
Points (72 per inch) p
Millimeters m
Centimeters c
Inches i or "
If the user doesn't type a unit of measurement with the number when prompted, WordPerfect uses WP Units as a default unit of measurement.
Using OLE object commands in macros
Commands for OLE objects are called methods, and they perform tasks on an OLE object in a specific OLE Automation server.
OLE object methods are specific for each object, such as "Excel.Application" or "Excel.Workbooks."
OLE object methods that return information about an object are called properties. Many properties have parameters as well as return values. In addition, many properties can be assigned a value, like the name of a variable, by placing them on the left-hand side of the assignment symbol ":=".
Compiling macros
You must compile a macro before you can play it. The programs that compile macros are called compilers. A macro compiler is used to compile or "translate" macros so that WordPerfect Office applications can play them. WordPerfect compiles a macro every time you save it.
Macros are written with an editor or word processor and saved as a source file. The macro compiler creates an object, which it saves in a hidden area of the source file (the macro compiler does not create a separate object file). When you edit the source file, the object is destroyed. The object is recreated each time the source file is compiled. A compiled source file (macro) contains instructions that are executed when you play the macro.
When you compile a macro, you might receive error messages which can indicate misspelled commands, missing parentheses or semicolons, and other syntax errors. If you receive an error message while the macro is compiling, you must correct all the errors before the macro will play. You can edit the macro to fix the errors.
WordPerfect macros have three types of errors: syntax errors, run-time errors, and logic errors.
Identifying syntax errors
Syntax errors appear when you are compiling a macro. The PerfectScript compiler flags unrecognizable commands, such as missing parentheses or semicolons and incorrectly spelled command names. For example, if you type Centr (WordPerfect command) instead of Center, a compile-time syntax error is displayed in a syntax error message box when you save and compile.
The compiler identifies syntax errors and suggests solutions. The error message displays information about the error and its location. The compiler makes a best guess and may not always be accurate. You must correct all errors before a macro can compile correctly. If you continue the compilation after an error is displayed, subsequent errors may be inaccurate.
Common syntax errors include
missing semicolons between parameters
missing parentheses
missing double quotation marks
missing command in a conditional or loop statement
misspelled macro command names
undefined calling statements
using commas between parameters instead of semicolons
Identifying runtime errors
Runtime is the same as execution time. Run-time errors occur while the macro is playing. Referencing a variable that has not been assigned a value causes a run-time error. Run-time error messages identify errors that occur while the macro plays and show where errors occur.
Identifying logic errors
When a macro does not produce the expected result, you may have a logic error. When a macro has a logic error, it plays without producing any error messages because WordPerfect accepts all of the macro commands.
Troubleshooting macro problems
The compiler can help you troubleshoot macro problems. If the compiler locates an error, a dialog box displays information about the problem. The compiler only directs you to the problem; it does not identify it.
The PerfectScript application has debugging features. For more information about PerfectScript, see the PerfectScript application online Help.
If you are writing or editing a macro, when you compile you change what is on screen to a language that PerfectScript can play. If you want PerfectScript to be able to read errors in the file, you must create a listing or log file. When you generate a listing file, PerfectScript saves it with a .wcl filename extension. If you want to debug PerfectScript macros using the PerfectScript debugger to tell you where the problems are located, you must set PerfectScript to produce a listing file every time you save and compile the macro. For more information about the PerfectScript debugger, see the PerfectScript online Help.
To compile a macro
Click the Save & compile button on the Macro toolbar.
If the Macro toolbar is not displayed, click Tools Macro Macro toolbar.
Note
If a macro you compile has error messages, WordPerfect still saves it even if you do not fix the compile errors.
To set PerfectScript to generate a listing file when you compile a macro
1 On the Windows taskbar, click Start Programs WordPerfect Office 11 Utilities PerfectScript.
2 Click Tools Settings.
3 Click the Compile tab.
4 Enable the Generate listing file check box.
To find macro errors using the PerfectScript debugger
1 Click Tools Macro Edit.
2 Choose a macro.
3 Click Edit.
4 Click where you want WordPerfect to begin debugging the macro.
5 Type Step (On!).
If you want to display a debug window, type Display (On!).
6 Click the Save & compile button on the Macro toolbar.
7 Type a filename and path in the Listing filename box.
Note
By default, listing files, which have a .wcl filename extension, are saved to the same location as the macro you are compiling.
Working from the PerfectScript utility
You can use PerfectScript either inside WordPerfect or from the PerfectScript utility, which is included with the WordPerfect Office utilities. You can also set the default macro folder and the PerfectScript editor. You must set the PerfectScript macro editor before you can edit a macro.
WordPerfect lets you test for errors from inside the PerfectScript utility. WordPerfect allows you several options for debugging macros. You can debug macros step-by-step so that the macro executes the current commands and stops at the next command. You can also debug macros with a breakpoint so that the macro executes all the commands in the macro until it reaches the breakpoint. Macro breakpoints are set by default to be the beginning of the macro, the end of the macro, and at any errors. WordPerfect also lets you debug a macro by briefly displaying or "animating" each command before it is executed.
Animation allows you to step through macros line by line, automatically bringing up the debugging dialog box at each step so you can check the variables and other calls. You can specify how long the debugger will pause before moving to the next step.
PerfectScript starts automatically when you record or play a macro from a Windows application that supports macros. If you play a macro for an application that is not running, PerfectScript automatically starts the application.
To start PerfectScript from the Windows Start menu
On the Windows taskbar, click Start WordPerfect Office Utilities PerfectScript.
To set the default macro folder in PerfectScript
1 In PerfectScript, click Tools Settings.
2 Click the General tab.
3 In the Macro folder box, click the Browse button.
4 Choose the drive and folder where you want to store the macro.
5 Click Select.
To set the PerfectScript editor
1 In PerfectScript, click Tools Settings.
2 Click the Edit tab.
3 In the Editor path/filename box, click the Browse button.
4 Choose the drive and folder where the editor is stored.
5 Click Open.
Tip
You can also edit macros by selecting a macro filename in Windows Explorer and clicking Edit from the QuickMenu.
Testing for errors from PerfectScript
WordPerfect lets you debug macros, step-by-step, with a breakpoint. You can also debug macros by briefly displaying or "animating" each command before it is executed.
To debug a macro step-by-step from PerfectScript
1 In PerfectScript, click File Debug Play.
2 Choose a macro.
3 Type a filename and path in the Listing filename box.
4 Click OK.
5 Click Debug Step into.
Note
You may need to repeat this procedure more than once, until the macro is debugged.
To set a macro breakpoint
1 Choose the line of the macro at which you want to insert a breakpoint.
2 Click Debug Breakpoint Add.
If you want to debug a macro with a breakpoint, click Debug Continue.
To animate a macro
1 Click Edit Settings.
2 Click the Debug tab.
3 In the Animate settings area, enable one of the following options:
'Runto' does 'step into'-executes the next single statement
'Runto' does 'step over'-executes the call of the label or routine without stopping until it has completed
4 Type a value in the Delay (seconds) box.
5 Click OK.
6 Click Debug Animate.
Tip
When correcting compilation errors, start at the beginning and first correct the errors that are obvious, leaving the others until later, as some of these errors may have been caused by an earlier error.
To view the meaning of commands from the PerfectScript Debugger
Point to a command line.
The command or variable name and definition display.
Editing and deleting macros
WordPerfect lets you edit and delete macros.
To edit a macro
1 Click Tools Macro Edit.
2 Choose the drive and folder where the macro is stored.
3 Click Edit.
4 Make any editing changes.
5 Click the Save & compile button on the Macro toolbar.
6 Click Options Close macro on the Macro toolbar.
To delete a macro
1 Click Tools Macro Edit.
2 Choose the drive and folder where the macro is stored.
3 Click a macro.
4 Press DELETE.
Searching in macros
WordPerfect provides a macro with searching capabilities by recording a search in a macro. WordPerfect lets you use all of its find and replace functionality when you are searching in a macro. For more information about Find and Replace features, see "Finding and replacing text."
To record a search in a macro
1 In the edit view of the macro, click where you want the search to begin.
2 Click Tools Macro Record.
3 Click Edit Find and replace.
4 In the Find box, type the text for which you want to search.
5 In the Replace box, type the text with which you want to replace the found item.
6 Click Tools Macro Record.
You can also
Search for codes In the Find box, click Match Codes, and insert the codes for which you want to search from the Codes dialog box.
Replace codes In the Replace box, click Replace Codes, and insert the codes that you want to use from the Codes dialog box.
Integrating with Microsoft Visual Basic for Applications
You can use Microsoft Visual Basic for Applications (VBA) with WordPerfect Office. VBA is an object oriented programming language that lets you create VBA macros to automate tasks. You can, for example, create a macro in WordPerfect that changes the color of the headings. VBA is not part of the typical install of WordPerfect Office. To use VBA, you should do a custom install and enable Microsoft Visual Basic For Applications.
You can program and play a project or a global VBA macro in WordPerfect. You can play a project macro only from the document that was used to create it. If the macro does not perform the desired action, you can debug the macro.
You can edit a VBA macro. Editing a macro involves going directly to the start of the code, whereas debugging a macro involves stepping through each line of the code.
Debugging is an extremely important part of the programming process. Debugging lets you step through your code line by line to ensure that the macro executes properly. This feature of programming is known as single-stepping. For example, if you are at a point in the code where a variable is about to be assigned a value, you can step into this line of code to determine the value of the variable at run-time.
For more information about VBA, see the Microsoft Visual Basic Help in the Visual Basic Editor.
Event-driven programming
Visual Basic for Applications 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.
The difference between PerfectScript and VBA
Previously, you could only use the PerfectScript language to automate specific tasks. Both product commands and programming commands are used in conjunction with the PerfectScript language. The PerfectScript language is useful for developing simple macros. VBA offers more flexibility and power. When you use VBA to create macros, you are assisted by the Visual Basic compiler. The compiler helps you by providing context-sensitive Help when you are coding a VBA macro. You can combine the power of VBA with the PerfectScript product commands to create powerful macros. You must use the Visual Basic Editor to create VBA macros; however, PerfectScript macros are developed from the WordPerfect Editor. You can access the Visual Basic Editor only when you are working in an active document.
The PerfectScript class
All product commands used in WordPerfect, Quattro Pro, and Corel Presentations can be used in VBA macros. You must call the PerfectScript object to access a product command. An object is an instance of a class. All objects have properties; for example, the name of a document is a property that belongs to the document object. You can set or change an object's properties by calling certain methods. A method performs a specific action, such as inserting a table into a document. You can, for example, close a document by calling the Close method, or you can save a document by calling the Save method. The term "class" is a VBA programming term and means a collection of related methods, which are referred to as class members. The product commands are the class members that belong to the PerfectScript class. WordPerfect, Quattro Pro, and Corel Presentations have their own PerfectScript class because the class members, which are the product commands, are different depending on the application.
All members of the PerfectScript class will perform a specific action. For more information about product commands, see the macros manual.
The syntax for the product commands and the PerfectScript members is usually the same; however, there may be some differences.
Working in the VBA Editor
In most cases, the name of the class is the same as the name of the object. WordPerfect Office has one object, which is the document object. In WordPerfect, the name of the document object is ThisDocument, which is the same as the class. In Corel Presentations, the name of the document object is ThisSlideShow, which is the same as the class. In Quattro Pro, the name of the document object is ThisDocument, which is the same as the class. The document object is the host application that is open. In future versions, there will be many more objects, such as a table object or a cell object.
You can create a new object, such as a dialog box, which is known as a form. You can add controls, such as a check box or a text box. You can set the object's properties in the Property dialog box located in the Visual Basic Editor. You can also set the object's properties at run time by programming a method. For example, you can color a form red when you click on it. For more information about setting an object's properties, see the Microsoft Visual Basic Help in the Visual Basic Editor.
An experienced programmer can work directly with the Windows API (Application Programming Interface) and, for example, be able to determine how much disk space is free or gain access to the system's time and date values. Most VBA users will want to automate specific and repetitive tasks.
Accessing an Application from another Application's macro
You can access and change an application from another application's macro. For example, you could create and use a Quattro Pro object from a WordPerfect VBA macro. This allows you to change and save a Quattro Pro document from a WordPerfect VBA macro.
Creating VBA macros
You can create two kinds of VBA macros: a global and a project macro. You can play a global macro from more than one document; however, a project macro can be played only in the document which was used to create it.
You can create a project VBA macro by creating a public method for the ThisDocument object. The term public refers to the access level. If a method is public, it can be accessed from outside the class. This means that you can call it from the host application. If a method is private, only methods in the same class can access it. Every public method that belongs to the ThisDocument class is a project macro. You can create a VBA macro called ShowMessage and code one line as follows: MsgBox "Hello". This VBA macro calls a Message Box that displays the string "Hello."
Using VBA macros
You can store a VBA macro in the document by saving the document. Once you have saved the document, you can close and reopen the document and access the macro. After you have developed the macro, you should debug it. You can step through each macro line by line. This is a useful exercise to ensure that the macro will have the desired outcome. A project macro is not available if the document is closed. After you have debugged the macro, you can play the macro.
Assigning security
When you open WordPerfect Office documents created by other users, be aware that a document could contain a macro virus. As a screening measure, VBA includes a security mechanism to help manage document security. You determine the security level used when opening or loading documents and add-ins containing embedded VBA macros. You can review the assigned security level and collection of trusted certificates that come from reputable sources. A VBA developer can attach his digital signature to a macro which creates a certificate when the document is opened. The fact that a document has a digital signature does not automatically ensure the document to be free of viruses, so that the onus is on you to find out if the developer scans for viruses before adding his certificate to your trusted sources.
There are three security level settings available: High, Medium, and Low. With the High setting, you can open a signed VBA project from a trusted source with the macros enabled. Otherwise, the document is opened with the macros disabled. The default security setting is Medium. A Medium setting indicates that a warning displays if you try to load a VBA document that is not on your trusted source list. You can choose to open the document with the macros enabled or disabled. The Low setting allows you to open all VBA projects without applying any security (which disables all virus protection).
To start VBA from WordPerfect
Click Tools Visual Basic Visual Basic Editor.
Note
The members of the PerfectScript class are applicable only to WordPerfect.
To display the VBA toolbar
1 Click View Toolbars.
2 Enable the Visual Basic check box.
To create a VBA project macro in WordPerfect
1 Click Tools Visual Basic Visual Basic Editor.
2 Double-click Project (Document1) 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, and 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 WordPerfect objects folder in the Project view.
8 Double-click ThisDocument, and type the following lines of code in the Editor box:
Public Sub ShowForm()
End Sub
This code adds a new method to the ThisDocument class. If you declare ShowForm as a Private method, you will not be able to run it from WordPerfect.
9 Type the following line of code in the ShowForm method:
Public Sub ShowForm()
UserForm1.Show
End Sub
To create a VBA global macro in WordPerfect
1 Click Tools Visual Basic Visual Basic Editor.
2 Double-click Global macros in the Project view.
3 Click Insert User form.
4 Change the form so that it resembles the diagram below the procedure.
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, and 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 WordPerfect objects folder in the Project view.
8 Double-click ThisDocument, and type the following lines of code in the Editor box:
Public Sub ShowForm()
End Sub
This code will add a new method to the ThisDocument class. If you declare ShowForm as a Private method, you will not be able to run it from WordPerfect.
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. For more information about VBA, see the Microsoft Visual Basic Help in the Visual Basic Editor.
To play a VBA macro in WordPerfect
1 Click Tools Visual Basic Play.
2 Choose one of the following macros from the Macros in list box:
ThisDocument-lets you play a project VBA macro
Global-lets you play a global VBA macro
3 Choose a macro from the Macro name list box.
4 Click Run.
Tip
To start a VBA macro, you can also click the Play button on the Visual Basic toolbar.
To edit a VBA macro
1 Click Tools Visual Basic Play.
2 Choose a macro from the Macro name list box.
3 Click Edit.
4 Edit the code as necessary.
To debug a macro created in VBA
1 Click Tools Visual Basic Play.
2 Choose a macro from the Macro name list box.
3 Click Step into.
4 For each line of code you want to step into, click Debug Step into.
5 Change the code as necessary.
Note
After you have stepped into a line of code, you can point to a specific variable to determine the value of the variable.
Using the PerfectScript class to change WordPerfect documents
The PerfectScript class lets you automate specific and repetitive tasks. The members of the PerfectScript class are the product commands that are used in conjunction with the PerfectScript language.
To create a VBA macro that uses the PerfectScript class
1 Click Tools Visual Basic Visual Basic Editor.
2 Double-click Project(Document1), and double-click the WordPerfect objects folder in the Project view.
3 Double-click ThisDocument, and type the following lines of code in the Editor window:
Public Sub AddWatermark()
UserForm1.Show
End Sub
This code will add a new method, called AddWatermark, to the ThisDocument class. Userform1 is the name of the form object. The Show method will call Userform1.
4 Click Insert User form, and change the form so that it resembles the following diagram:
The default names of the controls are used. Located on this form are a CommandButton and a ComboBox. 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.
5 Double-click on the form to access the Editor window, choose General from the Object list box, and add the following code in the Editor window:
Dim myStyle As String
This code will create a string variable called myStyle.
6 Choose Userform from the Object list box.
7 Choose Initialize from the Procedure list box, and add the following code in the UserForm_Initialize method:
Private Sub UserForm_Initialize()
ComboBox1.AddItem "Rose"
ComboBox1.AddItem "World"
ComboBox1.AddItem "Ribbon"
End Sub
This code responds to the event that occurs when the form is initialized. This code adds three string items to the ComboBox1 control.
8 Double-click the CommandButton1 control to create a new method for the UserForm1 class, and type the following lines of code in the CommandButton1_Click method:
Private Sub CommandButton1_Click()
myStyle = ComboBox1
If myStyle = "" Then
MsgBox "You have not selected a style", vbExclamation
This code responds to the event that occurs when you click the command button. Be sure to enter the correct path to where the graphics files are located.
Notes
In this procedure, a new method called AddWatermark is added to the ThisDocument class. This macro calls a form that lets you select a choice of three watermarks to insert into the odd pages of the document. PerfectScript class members can be accessed only by calling the PerfectScript object, which must be followed by a ".". You can call the AboutDlg method, which is a PerfectScript class member, by typing PerfectScript.AboutDlg.
You need three graphic files for this procedure. The names of these files are: world3.wpg, rose2.wpg, and ribb0002.wpg. These files are located in the C:\corel\WordPerfect Office 11\graphics\clipart\basic clipart folder. It is recommended that you place these files in the C:\ drive.
Working with VBA methods
You can use VBA to get system information, such as the system's date and time values. Retrieving the system's date and time values using VBA is very easy because all of the Windows functions are hidden, and all you have to do is call the appropriate VBA method.
To access the system's date and time values
1 Click Tools Visual Basic Visual Basic Editor.
2 Double-click Project(Document1) in the Project view.
3 Double-click the WordPerfect objects folder in the Project view.
4 Double-click ThisDocument, and type the following lines of code in the Editor box:
Public Sub ShowTime()
End Sub
This code will add a new method to the ThisDocument class. Make sure that the ShowTime method is declared public so that you can access this macro from WordPerfect.
5 Type the following new code in the ShowTime method to declare two new variables:
Public Sub ShowTime()
Dim myTime
Dim myDate As Date
End Sub
6 Type the following new code in the ShowTime method to populate the myTime and the myDate variables:
Public Sub ShowTime()
Dim myTime
Dim myDate As Date
myTime = Time
myDate = Date
End Sub
7 Type the following new code in the ShowTime method to convert the two variables to string data types:
Public Sub ShowTime()
Dim myTime
Dim myDate As Date
myTime = Time
myDate = Date
Dim myStrTime, myStrDate, Msg As String
myStrDate = Str(myDate)
myStrTime = Str(myTime)
End Sub
8 Type the following new code in the ShowTime method to populate and display the Msg variable:
Public Sub ShowTime()
Dim myTime
Dim myDate As Date
myTime = Time
myDate = Date
Dim myStrTime, myStrDate, Msg As String
myStrDate = Str(myDate)
myStrTime = Str(myTime)
Msg = "The date is " & myStrDateI & " and the time is " & myStrTime
MsgBox Msg
End Sub
Note
For the purpose of this procedure, a message box was selected to display the date and time (myDate, myTime, myStrDate, and myStrTime); however, you can create a new form and display the time and date in this form. For more information about VBA, see Microsoft Visual Basic Help in the Visual Basic Editor.
Accessing and manipulating applications from other applications
You can create a VBA macro that will call another application. It is possible to program a VBA macro to open and change another application at run time. For example, you can create a Quattro Pro object from the WordPerfect VBA Editor. This lets you create a WordPerfect VBA macro that will change a Quattro Pro document.
To create a WordPerfect VBA Macro that will manipulate a Quattro Pro document
1 Open WordPerfect, and click Tools Visual Basic Visual Basic Editor.
2 Double-click Project (Document1) in the Project view.
3 Click Tools, choose Reference, enable QuattroPro, and click OK.
Every application has an object. Make sure you reference the right object.
4 Double-click the WordPerfect objects folder in the Project view.
5 Double-click ThisDocument, and type the following lines of code in the Editor box:
Public Sub CreateQPTable()
End Sub
This code will add a new method to the ThisDocument class. Make sure that CreateQPTable is declared public so that you can access this macro from WordPerfect.
6 Type the following lines of code in the CreateQPTable method:
Public Sub CreateQPTable()
Dim myQp as Object
Set myQp = CreateObject("QuattroPro.PerfectScript")
If myQp Is Nothing Then
MsgBox "The Quattro Pro Object is invalid", vbCritical
End If
This code creates a Quattro Pro PerfectScript object. After the object is created, it is tested to determine if memory has been allocated to it. A Message Box will inform you if the object is invalid.
7 Type the following lines of code in the CreateQPTable method:
Public Sub CreateQPTable()
Dim myQp as Object
Set myQp = CreateObject("QuattroPro.PerfectScript")
If myQp Is Nothing Then
MsgBox "The Quattro Pro Object does not exist", vbCritical
End If
'Populate the Quattro Pro document
myQp.FileNew "FileNew"
myQp.SetCellString "B1", "Jan"
myQp.SetCellString "C1", "Feb"
myQp.SetCellString "D1", "Mar"
myQp.SetCellString "A2", "TVs"
myQp.SetCellString "A3", "VCRs"
myQp.SetCellString "A4", "Radios
End Sub
This code will create a new Quattro Pro document and create an inventory table.
Note
For the purpose of this procedure, a simple inventory table was created in a Quattro Pro document (myQP). You can run this macro from WordPerfect. For testing purposes, make sure that Quattro Pro is open. For more information about VBA, see Microsoft Visual Basic Help in the Visual Basic Editor.
Using OLE Automation
The Object Linking and Embedding (OLE) architecture is based on a model of client-server (also known as container-component or controller-component) associations. This model is based on the interaction between two applications in which one application (the client or container) makes requests to the other (the server or client) to perform an action. With OLE Automation, the application acting as the server exposes one or more automation components which allow other applications (controller or client) to manipulate them. For example, WordPerfect can execute a macro containing commands that open Microsoft Word, open a document into Microsoft Word, modify the formatting, resave the document, and close Microsoft Word. In this case, WordPerfect is the OLE automation controller and Microsoft Word is the OLE automation server, since it acts upon the requests made by WordPerfect. When Microsoft Word, Visual Basic for Applications (VBA), or any other OLE automation controller application opens WordPerfect and instructs it to perform certain specified tasks using OLE automation methods, WordPerfect is the OLE automation server and the controlling application becomes the OLE automation controller.
PerfectScript can send commands to WordPerfect, Corel Presentations, and Quattro Pro through OLE Automation. PerfectScript can also send commands to such applications as Microsoft Excel and Microsoft Word. These applications are called OLE Automation servers. PerfectScript is an OLE Automation controller. OLE Automation is not limited to these programs. PerfectScript can send commands to and control any OLE Automation server.
OLE Automation servers define objects. These objects have names that are registered with Windows. You can refer to an application's documentation for the names of objects they define. OLE objects can have methods and properties. A method is a command or function that performs an action on that object. A property is a value that the object has (like system variables in WordPerfect.) You can retrieve and set this value. An example of a method for the "Excel.Application" object is as follows:
Worksheets().Activate
A property of the "Excel.Application" object is as follows:
ActiveSheet.Name
Methods, like product commands, may require parameters, and may or may not return values. Unlike system variables in WordPerfect, you can set properties by placing the property name on the left-hand side of an assignment statement. Properties can also take parameters when being retrieved or when being set. This makes the retrieval of a property very similar to a method call.
Understanding OLE Automation
OLE Automation
OLE Automation for WordPerfect is a flexible and powerful feature you can use to quickly build applications that use WordPerfect components. OLE Automation is an integration standard that has developed to allow applications to "expose" their programmable objects so that other applications can access them. The exposed commands become an extension of the controlling programming language.
Applications that support OLE Automation are called OLE Automation servers. Programming applications that can use a server's scripting or macro commands are called OLE Automation controllers.
As shown in the following diagram, an OLE Automation server application exposes its programmable objects to the OLE Automation controller. The OLE Automation controller incorporates the server application's scripting or macro commands as part of its own language. The controller can send these commands back to the server.
You can use OLE Automation for long and complicated manual processes that transfer data between two or more applications. For example, you may have a manual process that puts data into a spreadsheet to be used to create a presentation graphic. The graphic is used in a word processing application. If you use OLE Automation, you may be able to create a program that automatically does these steps for you. OLE Automation gives you almost total control over a variety of different applications, letting you build the applications you need through its seamless integration capabilities.
At a basic level, you can think of OLE Automation as a way for applications to speak to and control each other through their own scripting or macro programming languages. For example, you could have WordPerfect speak to and control Microsoft Word, another OLE Automation server. Because WordPerfect, in this case the OLE Automation controller, is a desktop publishing application and does not know about the inner workings of Microsoft Word, the OLE Automation server, it needs a way to get information from the server.
Conversely, WordPerfect can be controlled by other OLE Automation applications through its PerfectScript application commands and a programming language. Some of the most widely used programming languages can support OLE automation, including Microsoft Visual Basic, Microsoft Visual Basic for Applications, and C++.
WordPerfect, PerfectScript, and OLE Automation
If you have ever used a script to send commands to WordPerfect or another Corel application, you've used OLE Automation. When you run a script that sends commands to a Corel application, you must use the WithObject statement to enable a programmable object in the application.
Any Corel application, including WordPerfect, that supports OLE Automation provides one programmable object that allows the PerfectScript controller to send it commands. The following table lists all of the Corel applications that support OLE Automation (and PerfectScript) and the name of their programmable object:
Corel application Programmable object name
Corel Presentations Presentation.PerfectScript
WordPerfect WordPerfect.PerfectScript
Quattro Pro QuattroPro.PerfectScript
CorelDRAW 8 CorelDraw.Automation
Corel PHOTO-PAINT 8 CorelPaint.Automation
Corel VENTURA 8 CorelVentura.Automation
Since the Corel applications listed above provide one programmable object, their documents cannot be directly accessed as objects from a controller. The Microsoft Visual Basic GetObject command, for example, cannot be used to access a Corel document. Additionally, Corel applications do not support properties and methods. The only way to access a Corel document through OLE Automation is by using PerfectScript application commands.
You can also use other scripting languages to call Corel OLE Automation applications. For example, you can call the WordPerfect object using a script created in Visual Basic. The following Visual Basic script creates a new WordPerfect document and inserts a footnote.
Private Sub Form_Load()
Dim objWP As Variant
Set objWP = CreateObject("WordPerfect.PerfectScript")
objWP.FootnoteCreate
objWP.Tab
objWP.Type "This was inserted with VB."
objWP.Quit
End Sub
As in the example above, the Microsoft Visual Basic commands, or any other OLE automation application commands, must be preceded by an application name and a period.
Other OLE Automation controllers
Rather than using only PerfectScript, you can use other applications as your OLE Automation controller. For example, you can use Microsoft Visual Basic, Microsoft Visual Basic for Applications, or Microsoft C++ as your OLE Automation controller for Corel applications. However, if you use a programming language other than PerfectScript to send commands to Corel applications, you cannot use PerfectScript programming statements and functions such as FOR...NEXT or MESSAGE, or Corel dialog box definition statements; you can only use the Corel application commands.
For information about commands and functions and PerfectScript OLE Automation overviews, see the online Help in the respective application. However, it does not provide procedural and reference information about programming by using OLE automation controllers other than PerfectScript. For more information about other OLE automation controllers, see the following reference sources:
Microsoft Visual Basic Programmer's Guide
Microsoft Windows Developer's Kit
Microsoft Office Developer's Kit
The PerfectScript command Quit is specifically for use with OLE Automation. If you are scripting languages such as Visual Basic, C, C++, Delphi, FoxPro, and Corel Script, you should use the Quit command at the end of the script. Because WordPerfect hosts VBA, the Quit command should not be used from VBA.
Using files with DDE Execute from previous versions of WordPerfect
Older versions of WordPerfect, such as WordPerfect 5.1 and WordPerfect 6.1, use Dynamic Data Exchange (DDE) Execute to trade information or allow one application to instruct another to perform specific tasks.
To use DDE Execute you need to refer to:
the WordPerfect macros Help file for information about the ddeinitiate(), ddeexecute(), and ddeterminate() programming commands
the documentation for the other Windows applications; the information you need includes the service (application) name, topic name, and list of commands the application will accept through DDE Execute
Sending commands to other Windows applications
Using DDE you can create WordPerfect macros that send commands to control other applications running under Windows. For example, you can create a macro that launches a spreadsheet application, loads a file, and copies a range of cells to a table in WordPerfect.
Sending commands to WordPerfect
Other applications can also use DDE Execute to control WordPerfect. The application must first initiate a DDE conversation using the service (application) name of "WPWin11_Macros" and topic name of "Commands." Before terminating the conversation, the application can send DDE Execute strings made up of one or more WordPerfect macro commands. Note that WordPerfect accepts only product commands, not programming commands. These product commands cannot contain variables or expressions. See the WordPerfect Macros Help file for a list of product commands and descriptions.
Other applications can also send commands to WordPerfect as a DDE Request item in order to receive a string representing the command's return value. The application must send the DDE Execute string or DDE Request item in ANSI text format. WordPerfect returns the DDE Request result as an ANSI text string. If either a DDE Execute string or a DDE Request item returns an error, the application can send a DDE Request on the item "LastCmdError" to find out what error occurred. This item will return an ANSI text string containing a three-digit error code and a description of the error.
DDE Execute application names, services, and topics
Application Service, Topic
WPWin WPWin11_Macros,PS3Commands
Presentations WPPresentations,Command
Quattro Pro QPW, <full path and filename of open notebook>
Getting online Help for macros
You can get online Help for macros through the macro command browser and the context-sensitive Help.
You can easily display the lists of product and programming commands for all applications in WordPerfect Office by using the WordPerfect Macros Help and the WordPerfect Office Macro Command Reference Center.
WordPerfect gives you instant Help on any command as you edit a macro. In the macro command browser, a brief description of the macro command appears at the bottom of the dialog box.
Online Help for each command in the macro command browser is available.
To start WordPerfect Macros Help
Click Help Macro commands.
To get more information about PerfectScript Commands
Click Help Help topics.
To display Help while editing a macro
1 Click in a command.
2 Press F1.
To get Help in the macro command browser
1 Choose a command from the Commands list.
2 Right-click the command to view the Help topic associated with that command.