August 1999: Recording a VB Script Macro
As you probably know, WordPerfect 9 now supports VBScript, in addition to PerfectScript. There is not a lot of information available yet on how the VBScript works in WordPerfect. This article will give a brief ovrview of how to record a macro in VBScript.
It is not outwardly apparent that you can actually record a VBScript macro. In fact, you can record the code that will go in a VBScript macro, but you'll still need to paste it manually into the VB Editor. Here's how:
- Click the Windows Start button, then select Programs > WordPerfect Office 2000 > Utilities > PerfectScript 9.
- Click Tools > Settings.
- Click the Record tab.
- In the Script language dropdown, select Visual Basic.
- Click OK to close the dialog, then close the PerfectScript utility.
-
Now start WordPerfect and click Tools > Macro > Record.
- Type a name for your macro, such as VBTEST.WCM, then click Record.
- Perform some actions, such as selecting a font style and size, type some text, add a hard return, and so on.
- When you are done, click Tools > Macro > Record to turn macro recording off. You'll be asked for a filename to convert to. Accept the specified name. If you get a compiler error, just click Cancel.
Clear your screen, then click Tools > Macro > Edit and select the macro you just created. When the macro appears on screen, you'll see code similar to the following:
Dim objWordPerfect As Variant
Set objWordPerfect = CreateObject ("WordPerfect.PerfectScript")
objWordPerfect.Font "Verdana ", 16640, 0, 90, 0, 20, 139, 0,
objWordPerfect.FontSize 0.194"
objWordPerfect.Type "This is a "
objWordPerfect.AttributeAppearanceToggle 12
objWordPerfect.Type "Visual Basic"
objWordPerfect.AttributeAppearanceToggle 12
objWordPerfect.Type " recording."
objWordPerfect.HardReturn
objWordPerfect.FontSize 0.153"
objWordPerfect.Type "Where am I allowed to go today? "
objWordPerfect.HardReturn
The VBScript code above is the equivalent of:
Application (WordPerfect; "WordPerfect"; Default!; "EN")
Font (Name: "Verdana ")
FontSize (FontSize: 0.194")
Type (Text: "This is a ")
AttributeAppearanceToggle (Attrib: Bold!)
Type (Text: "Visual Basic")
AttributeAppearanceToggle (Attrib: Bold!)
Type (Text: " recording.")
FontSize (FontSize: 0.153")
HardReturn ()
Type (Text: "Where am I allowed to go today? ")
HardReturn ()
Now to copy this code to the Visual Basic Editor,
- Select the code and press Ctrl+C to copy it.
- Close the macro.
- Click Tools > Visual Basic > Visual Basic Editor.
- In the Project window, click the plus sign next to VBAProject to display the items below it.
- Double click the ThisDocument item. A code window will appear.
- Type Public Sub MyMacro(), then press (Enter). VBA will insert an End Sub.
- Between the two lines of code, press (Ctrl+V) to copy your VBA code into the VBA editor.
- If you see some lines in red, there is a syntax error on that line. Check for a comma or quote mark at the end of that line and remove it. The red should go away.
- Click the Save toolbar button and save to VBTEST.WPD.
Your VBA macro is complete. Click the WordPerfect icon on the toolbar to return to WordPerfect. Click Tools > Visual Basic > Play. The VBA Macros dialog will appear. Make sure that VBAProjects is selected in the Macros in edit box. Your macro, called MyMacro should appear in the macro name list. Select it and click Run.
Remember to go back into PerfectScript and change the recording language back to PerfectScript if you wish to record PS macros later.
We'll cover additional VBA topics inthe future. If you have questions about the general workings of VBA, email me. I can't guarantee I'll answer your question in this column, and I can't respond to everyone, but your questions will give me an idea of what topics you'd like to see covered here.

Copyright Notice: The information included in the PerfectScript Journal is protected
by US Copyright. The author grants you the right to use the routines in your own macros as
needed. You may not sell, distribute, or publish them in any form.
If you choose to use the information here, you do so entirely at your own risk. No
representations are made regarding the fitness of this information for your particular
purpose, or for your ability or inability to use the information. You are advised to make
backups of all relevant files before implementing any suggestion or technique.
© Copyright 1999 by J. Jeppson.