Export (0) Print
Expand All

Converting WordBasic Macros to Visual Basic

Office 2003

Microsoft Office Word 2003 automatically converts the macros in a Word 6.x or Word 95 template the first time you do any of the following:

  • Open the template
  • Create a new document based on the template
  • Attach the template to a document by using the Templates command (Tools menu).

A message is displayed on the status bar while the macros are being converted. After the conversion is complete, you must save the template to save the converted macros. If you don't save the template, Word converts the macros again the next time you use the template.

Note  Office Word 2003 cannot convert Word 2.x macros directly. Instead, you need to open and save your Word 2.x templates in Word 6.x or Word 95 and then open them in Office Word 2003.

The conversion process converts each macro to a Visual Basic module. To see the converted macros, point to Macro on the Tools menu and click Macros. The macro names in the Macros dialog box appear as macroname.Main, where Main refers to the main subroutine in the converted macro (the subroutine that began with Sub MAIN in earlier versions of Word). To edit the converted macro, select a macro name and click Edit to display the Visual Basic module in the Visual Basic Editor.

Each WordBasic statement is modified to work with Visual Basic for Applications. The converted WordBasic macros are functionally equivalent to new Visual Basic for Applications macros you might write or record, but they are not identical. The following example is a WordBasic macro in a Word 95 template.

    Sub MAIN
FormatFont .Name = "Arial", .Points = 10
Insert "Hello World"
End Sub
  

When the template is opened in Word, the macro is converted to the following code.

    Public Sub Main()
WordBasic.FormatFont Font:="Arial", Points:=10
WordBasic.Insert "Hello World"
End Sub
  

Each statement in the converted macro begins with the WordBasic property. WordBasic is a property in the Office Word 2003 object model that returns an object with all the WordBasic statements and functions; this object makes it possible to run WordBasic macros in Office Word 2003.

Note  If you save the template over the original template, the WordBasic macros will be permanently lost and previous versions of Word will not be able to use the converted macros.

The following Visual Basic macro is functionally the same as the preceding WordBasic macro, but doesn't use the WordBasic property.

Public Sub Main()
    With Selection.Font
        .Name = "Arial"
        .Size = 10
    End With
    Selection.TypeText Text:="Hello World"
End Sub
		


See Also | WordBasic Property


Show:
© 2014 Microsoft