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 spreadsheet.
To create a WordPerfect VBA Macro that can manipulate a Quattro Pro spreadsheet
| |
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()
|
|
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()
|
|
Set myQp = CreateObject(“QuattroPro.PerfectScript”)
|
|
MsgBox “The Quattro Pro Object is invalid”, vbCritical
|
|
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()
|
|
Set myQp = CreateObject(“QuattroPro.PerfectScript”)
|
|
MsgBox “The Quattro Pro Object does not exist”, vbCritical
|
|
'Populate the Quattro Pro document
|
|
myQp.SetCellString “B1”, “Jan”
|
|
myQp.SetCellString “C1”, “Feb”
|
|
myQp.SetCellString “D1”, “Mar”
|
|
myQp.SetCellString “A2”, “TVs”
|
|
myQp.SetCellString “A3”, “VCRs”
|
|
myQp.SetCellString “A4”, “Radios”
|
|
This code will create a new Quattro Pro document and create an inventory table.
|
•
|
|
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.
|
Accessing and manipulating applications from other applications