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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Update a Word bookmark from Access VBA Please please help

Status
Not open for further replies.

MooYai

Technical User
May 16, 2003
12
DE
In Access I create a MS Word file by copying it from a Template then I open it with a Hyperlink (Follow...). This works fine. Then I would like to update some bookmarks in the new MS Word Document but I don't know how to do it. I already tried something like

Dim appWord As Object

Set appWord = CreateObject("Word.Basic")
appWord.fileopen FileName ' Open your document, etc

appWord.ActiveDocument.Goto What:=wdGoToBookmark, Name:="Originator"
appWord.ActiveDocument.Insert "Thomas"


but I get an error on the wdGotoBookmark thing.

Does anybody know an easy way to write text to a specifc bookmark in a Word Document ??

Any answer is welcome and highly apreciated.
Please help. I've been trying for months now !! Please Please
 
Hi MooYai,

Try using Word.Application instead of Word.Basic, and do ...

Code:
Dim appWord As Word.Application

Set appWord = CreateObject("Word.Application")
appWord.Documents.Open FileName
appWord.Selection.Goto What:=wdGoToBookmark, Name:="Originator"
appWord.Selection.TypeText "Thomas"
appWord.ActiveDocument.Save
appWord.ActiveDocument.Close
Set appWord = Nothing

Enjoy,
Tony
 
Thanks for your answer but when I try
"Dim appWord As Word.Application" I get a compile error:
"User deined Type not defined". I understood that it does not recognise the type Word.Application. Is here a way to teach Access that it should know about this application type ?


Thomas
 
Hi MooYai,

You need to have a reference to Word. In the module editor go to Tools > References, and make sure "Microsoft Word x.x Object Library" is checked. This will show VBA all the Word Objects. Alternatively you can just change the code to Dim appWord as Object (or just "Dim appWord" if you want) - but the first way is better.

Enjoy,
Tony
 
Hi Tony,

Thanks for your help. I thought I had ticked the Object Library but apparently I hadn't. yesterday after your first post I was trying to find it again but I could not remember where to look it up and tick it. So again many thanks for your help. It will certainly make my users happy.

Thomas
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top