Microsoft KB Archive/181394

= WD98: Writing Macro Code for VBA and WordBasic Branching =

Article ID: 181394

Article Last Modified on 6/17/2005

-

APPLIES TO


 * Microsoft Word 98 for Macintosh

-



This article was previously published under Q181394





SUMMARY
This article includes sample Microsoft Visual Basic for Applications code that demonstrates how to determine the version of Word currently installed when using Automation. Based on the version of Word, the code conditionally branches to use WordBasic commands if the version of Word is earlier than Word 97 for Windows or Word 98 Macintosh Edition. If the version of Word returned is equal to or greater than Word 97 for Windows or Word 98 Macintosh Edition, the code branches to use Visual Basic for Applications commands.

You may want to use this conditional branching if you are using more than one version of Word on your computer.



MORE INFORMATION
Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements. In the versions of Word listed at the beginning of this article, WordBasic has been replaced with Visual Basic for Applications. For backward compatibility, Visual Basic for Applications contains a WordBasic object. To ensure that the WordBasic command and arguments are positioned correctly, use the Position.hlp file for Word for Windows version 6.x.

NOTE: If your programming language was written to call WordBasic commands, and you are anticipating interacting with the Microsoft Word Visual Basic for Applications language for all future development needs, you should convert your code from WordBasic to Microsoft Word Visual Basic for Applications. ' ******************************************************************  ' MODULE NAME: Coding For WordBasic or Visual Basic Based on Version ' DECLARATIONS SECTION ' ******************************************************************  Dim oWordWB As Object Dim oWordVBA As Object

' The GetWordVersion routine creates a WordBasic object. It then ' determines the currently installed version of Word. ' If the version is earlier than Word 97, it branches to use a  ' WordBasic Code" routine. If the version is Word 97 or later, it   ' branches to use a Visual Basic for Applications routine. If Word is   ' not currently installed, an error is trapped and the program displays   ' a message and ends.

Sub GetWordVersion

' *******************************************************     ' PURPOSE: To determine the Word version and branch '         conditionally based on the version returned. '     ' ARGUMENTS: '          oWordWB - WordBasic Object ' *******************************************************

On Error GoTo NoWord Set oWOBJ = CreateObject("Word.basic")

If Val(oWOBJ.AppInfo(2)) < 8 Then

' If earlier than version 8, branch to WordBasic code. UseWordBasicCode

Else

' If version 8 or later, branch to Visual Basic for ' Applications code. UseVBACode

End If

NoWord: If Err <> 0 then MsgBox "Word is not installed." End End If  End Sub

Sub UseVBACode

' *********************************************************        ' PURPOSE: Used for Visual Basic For Applications commands. '        ' ARGUMENTS: '          oWordWB  - WordBasic Object '          oWordVBA - Visual Basic for Applications Object ' *********************************************************

' Close the WordBasic object that was used to determine the ' Word version. oWordWB.FileExit Set oWordWB = Nothing

' Create a Word Visual Basic for Applications object. Set oWordVBA = CreateObject("Word.Application")

' ***********************************************        ' < Visual Basic For Applications Commands Here > ' ***********************************************

' When quitting an Automation session with Visual Basic for ' Applications, you must use the Quit command in combination with ' setting the object to Nothing to clear the instance from memory. oWordVBA.Quit Set oWordVBA = Nothing

End Sub

Sub UseWordBasicCode

' *************************************        ' PURPOSE: Used for WordBasic commands. '        ' ARGUMENTS: '          oWordWB - WordBasic Object ' *************************************

' **************************        ' < WordBasic Commands Here> ' **************************

' Close the instance of Word. oWordWB.FileExit

' Clear the object from memory. Set oWordWB = Nothing

End Sub

