Solved

Moving to bookmark in Word 2007 template opened from Access 2007

Posted on 2009-06-30
5
444 Views
Last Modified: 2013-11-27
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.Count) 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\Michael\Documents\testaccessworddoc.docx" it will not open the document (just keeps the Word instance open)
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

Open in new window

0
Comment
Question by:databasefun
  • 3
  • 2
5 Comments
 
LVL 46

Expert Comment

by:tbsgadi
ID: 24752622
Hi databasefun,

Should be

With appWord.Selection
.GoTo What:=wdGoToBookmark, Name:="clientname"

Good Luck!

Gary
0
 

Author Comment

by:databasefun
ID: 24757100
I have already tried that as well and the cursor just stays at the beginning of the document
0
 

Author Comment

by:databasefun
ID: 24765712
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.Application")
             If Err Then
                  MsgBox "Can't start Word!"
                   Exit Sub
             End If
             appWord.Visible = True
      End If

appWord.Documents.Open ("C:\Users\Michael\Documents\testaccessworddoc.dotx")

  With appWord.activedocument.bookmarks
  .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.

 
0
 

Accepted Solution

by:
databasefun earned 0 total points
ID: 24766300
Figured it out.

The Microsoft Word 12.0 Object Library was not checked.  Once checked things worked fine.
0
 
LVL 46

Assisted Solution

by:tbsgadi
tbsgadi earned 100 total points
ID: 24766670
Yup that would do it :>
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Top 1 of each supplier 55 54
VBA SQL statement - 2 "OR"s and 1 "And" 4 24
SQL Group on First occurrence 9 23
Help with DoEvents 8 23
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

816 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now