Article ID: 163618
Article Last Modified on 1/19/2007
' ******************************************************************
' 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 for Windows.
' 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 OLE session with Visual Basic For Applications,
' you must use the Quit command in combination with setting
' the OLE 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
Additional query words: wordcon vb vbe vba
Keywords: kbcode kbfaq kbhowto kbinterop kbprogramming KB163618