Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

WORD Automation Dilemma...still hovering over me...

Status
Not open for further replies.

TekRite

Technical User
Sep 25, 2005
17
US
I am still stuck with my problem...The code that I generated for a Command Button <cmdImpResTer> works great.

It CREATES an instance of WORD...OPENS the specified document...then goes to the specified page...wdGoToPage.

My problem is that when I use the code again for another Command Button <cmdNotRevTer>...it only OPENS the specified document...but it does NOT GoTo the specified page.

I tried PH's suggestion of using Option Explicit to force the declaration by placing 'Dim Wd' into my code...but that did not seem to make a difference.

Here is the code that works fine:

Private Sub cmdImpResTer_Click()
'
'Import Resources Procedures - page/section locator for OSO001001_TtMngPro
''Make sure that MS Word 9.0 Object(or higher) 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
'
Set Wd = CreateObject("Word.Application")
Wd.Visible = True
'
For Each doc In Wd.Documents
If doc.Name = "OSO1001_TtMngPro.doc" Then Found = True
Next doc
If Found <> True Then
Wd.Documents.Open "C:\My Documents\WORD documents\OSO1001_TtMngPro.doc"
Wd.Selection.GoTo What:=wdGoToPage, Count:="37"
Else
Wd.Selection.GoTo What:=wdGoToPage, Count:="37"
End If
'
End Sub

Here is the code that OPENS the specified document...but will not GoTo the specified PAGE:

Private Sub cmdNotRevTer_Click()
'
'Notification Review Procedures - page/section locator for OSO001001_TtMngPro
''Make sure that MS Word 9.0 Object(or higher) 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
'
Set Wd = CreateObject("Word.Application")
Wd.Visible = True
'
For Each doc In Wd.Documents
If doc.Name = "OSO1001_TtMngPro.doc" Then Found = True
Next doc
If Found <> True Then
Wd.Documents.Open "C:\My Documents\WORD documents\OSO1001_TtMngPro.doc"
Wd.Selection.GoTo What:=wdGoToPage, Count:="36"
Else
Wd.Selection.GoTo What:=wdGoToPage, Count:="36"
End If
'
End Sub

I cannot figure out what I am doing wrong...and/or not doing. Any suggestions? This code has become a "KEY" element to this project...so currently...I am "LOCKED OUT"...so to speak.

Any replies would be greatly appreciated...THANK YOU!

Garry


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top