| SUMMARY: | This document reviews how to find the correct Visual Basic for Application syntax needed in Word and how to convert it into the correct PowerBuilder syntax. Includes: - Code examples to see the PowerBuilder syntax for Word 8 OLE automation. - Incomplete list of VisulaBasic constants and their values for PowerBuilder |
| Document ID: | 47980 | Last Revised: | 10/28/99 |
| Topic: | App Development | Document Type: | TechNote |
| Product: | PowerBuilder | Version: | 7.0; 6.0; 5 |
| Platform: | PC | Operating System: | Windows 95, Windows NT, Windows 98 |
Document:
1. How to find the correct Visual Basic for Applications (VBA) syntax needed in Word and how to convert it into the correct Powerbuilder syntax
With Word 8 / Office 97, Microsoft changed the way applications communicate with Word via OLE. Old WordBasic syntax may not work properly and converting them to VBA equivalents may be required.
1.1 Use the Word macro Editor
An easy way to determine the VBA functions and their syntax by using the macro editor which is integrated in Word. To obtain the VBA functions turn on the macro recording in Word, perform the tasks you wish the macro to perform (ie. Highlight some text), and then turn off the recording. With ALT + F11 you are able to open the macro editor and see the syntax used by Word.
To get a complete description of a function and to see the complete syntax you can use the help file VBAWRD8.HLP which is available through a custom installation of Word (you must specify to install this help file during the installation process, it is not installed by default). Here you will find information regarding the functions you can use in Word and their VBA and WordBasic syntax. Furthermore you will be instructed which functions you can use with Word 8.
1.2 Convert VB Syntax to the PowerBuilder Syntax
- Hints:
a. PowerBuilder uses square brackets for array indices
b. Functions with several values are separated by comma between round brackets
Convertion example :
Here you see a macro recorded with the macro editor in Word.
Sub Macro1()' VB Syntax in a macro
Selection.MoveLeft Unit:=wdCharacter, Count:=5
' see hint a.
Selection.Information(wdWithInTable)
' see hint b.
' function without values
Selection.TypeBackspace
End Sub
From the VBAWRD8.HLP file, here is the definition of the MoveLeft() function used in the macro:
Selection.MoveLeft(Unit, Count, Extend)
Unit optional Variant: wdCell, wdCharacter, wdWord or wdSentence. Default = wdCharacter.
Count optional: . Number of Units to move. Default = 1.
Extend optional: wdMove or wdExtendHere is the syntax to call the MoveLeft() function
// PB syntax
ole_object.selection.Information[12]
ole_object.selection.MoveLeft(1,5,1)
ole_object.selection.TypeBackspace()
i.e.
Sub Makro1()
' this is a small messagebox to find out the integer
' value of an enumerated datatype in Word.
' in this case the value 5
Answer = MsgBox(wdLine, 0)
End Sub
Alternatively, Micorosoft's support website has a technical article which documents all of the constants and their numerical equivalents that may be found in Microsoft Office. The article is ID# Q112671.
In PowerBuilder, you would pass the actual value of the Word constant to the function. You can also declare a constant in PowerScript and associate it with the same value; when calling the Word function, pass it the constant you declared instead of the actual value. This allows you to make global changes easily to your code if Microsoft decides to change what the value of the Word constant in future releases.
Under section 3. you find a list with common constants and their numeric equivalents.
1.3 The Word Object Model
共2页 1 2






