The problem I am having with the code below seems to be with its "reusablity" with subsequent Command Buttons. The code "works fine...lasts a long time" with the initial Command Button it is assigned to...
but when I copy and paste it to another Command Button I get either a 'Compile Error' "Variable not defined" with a reference to 'wdGoToPage' as the supposed undefined variable
OR
The code OPENS the specified document but does not GOTO the page specified in the GoTo Method.
The Command Buttons are inserted on Visio drawings for the purpose of Creating an instance of WORD...Opening the specified document...and going to the Page specified with the What:=wdGoToPage, Count:="page#".
Here is the code that works...but only for this one button:
Option Explicit
Private Sub cmdImpResTer_Click()
'
'Import Resources Procedures - page/section locator for OSO001001_TtMngPro
'Make sure that MS Word 11.0 Object is available by selecting <tools>
''then <references> and then selecting the checkbox next to MS Word 9.0, 10.0 or 11.0 Object
'
Dim Wd As Object
'
Set Wd = CreateObject("Word.Application")
Wd.Visible = True
'
Dim Found As Boolean
Dim doc As Document
'
For Each doc In Wd.Documents
If doc.Name = "OSO1001_TtMngPro.doc" Then Found = True
Next doc
If Found <> True Then
Wd.Documents.Open "\\Svfulcommon1\Salesprojdoc\9 - Documentation\OSO Procedures\Internal\Procedures\Territory Management\OSO1001_TtMngPro.doc"
Wd.Selection.GoTo What:=wdGoToPage, Count:="39"
Else
Wd.Selection.GoTo What:=wdGoToPage, Count:="39"
End If
'
End Sub
Can anyone solve this for me?
Garry
but when I copy and paste it to another Command Button I get either a 'Compile Error' "Variable not defined" with a reference to 'wdGoToPage' as the supposed undefined variable
OR
The code OPENS the specified document but does not GOTO the page specified in the GoTo Method.
The Command Buttons are inserted on Visio drawings for the purpose of Creating an instance of WORD...Opening the specified document...and going to the Page specified with the What:=wdGoToPage, Count:="page#".
Here is the code that works...but only for this one button:
Option Explicit
Private Sub cmdImpResTer_Click()
'
'Import Resources Procedures - page/section locator for OSO001001_TtMngPro
'Make sure that MS Word 11.0 Object is available by selecting <tools>
''then <references> and then selecting the checkbox next to MS Word 9.0, 10.0 or 11.0 Object
'
Dim Wd As Object
'
Set Wd = CreateObject("Word.Application")
Wd.Visible = True
'
Dim Found As Boolean
Dim doc As Document
'
For Each doc In Wd.Documents
If doc.Name = "OSO1001_TtMngPro.doc" Then Found = True
Next doc
If Found <> True Then
Wd.Documents.Open "\\Svfulcommon1\Salesprojdoc\9 - Documentation\OSO Procedures\Internal\Procedures\Territory Management\OSO1001_TtMngPro.doc"
Wd.Selection.GoTo What:=wdGoToPage, Count:="39"
Else
Wd.Selection.GoTo What:=wdGoToPage, Count:="39"
End If
'
End Sub
Can anyone solve this for me?
Garry