databasefun
asked on
Moving to bookmark in Word 2007 template opened from Access 2007
I want to open a Word template from Access and then navigate to a bookmark. I can open the template just fine and I can use things like .TypeText Text:="This is a test", but it will not navigate to a bookmark. If I do a count bookmarks (X = ActiveDocument.Bookmarks.C ount) if will return 0 even though if you go to the Word document that is opened by Access and open bookmarks it will show the bookmark I am trying to navigate to (and if I click it it will go to the bookmark just fine).
I have enabled macros in the template. I have also tried variants of the command line I use to .Goto what, but without making a difference. Also tried the MoveUp command to see if that would work and it did not.
Another strange thing is I can open a template document, but if I try to open an existing document using
appWord.Documents.Open FileName:="C:\Users\Michae l\Document s\testacce ssworddoc. docx" it will not open the document (just keeps the Word instance open)
I have enabled macros in the template. I have also tried variants of the command line I use to .Goto what, but without making a difference. Also tried the MoveUp command to see if that would work and it did not.
Another strange thing is I can open a template document, but if I try to open an existing document using
appWord.Documents.Open FileName:="C:\Users\Michae
With appWord.Documents.Add(Template:="c:\Users\Michael\Documents\testaccessworddoc.dotx")
End With
With appWord.Selection
Selection.GoTo What:=wdGoToBookmark, Name:="clientname"
appWord.Selection.MoveUp wdline, 6
End With
ASKER
I have already tried that as well and the cursor just stays at the beginning of the document
ASKER
Found a workaround. If I use the following it fills in the bookmark just fine.
Dim appWord As Object
Set appWord = GetObject(, "Word.Application")
If Err Then
Err.Clear
Set appWord = CreateObject("Word.Applica tion")
If Err Then
MsgBox "Can't start Word!"
Exit Sub
End If
appWord.Visible = True
End If
appWord.Documents.Open ("C:\Users\Michael\Documen ts\testacc essworddoc .dotx")
With appWord.activedocument.boo kmarks
.Item("clientname").range. Text = "Why me"
End With
If I use in the With structure the command
.GoTo What:=wdGoToBookmark, Name:="clientname"
it will not navigate to the bookmark. The cursor just stays at the document top and if I start entering text it goes at the start of the document.
Dim appWord As Object
Set appWord = GetObject(, "Word.Application")
If Err Then
Err.Clear
Set appWord = CreateObject("Word.Applica
If Err Then
MsgBox "Can't start Word!"
Exit Sub
End If
appWord.Visible = True
End If
appWord.Documents.Open ("C:\Users\Michael\Documen
With appWord.activedocument.boo
.Item("clientname").range.
End With
If I use in the With structure the command
.GoTo What:=wdGoToBookmark, Name:="clientname"
it will not navigate to the bookmark. The cursor just stays at the document top and if I start entering text it goes at the start of the document.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Should be
With appWord.Selection
.GoTo What:=wdGoToBookmark, Name:="clientname"
Good Luck!
Gary