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

Word Bookmark Syntax in Excel VBA

Status
Not open for further replies.

Dawber

Technical User
Jun 29, 2001
86
GB
I am using an Excel spreadsheet to fill in certain bookmarks in a Word document. I am trying to use the following, without success.

Code:
Selection.GoTo What:=wdGoToBookmark, Name:="project"
Selection.TypeText Text:="xxx"

Without these lines, the macro operates as expected, opening and closing the Word aplication. However, as soon as this is introduced, I receive an error message (Run-time error 438 - Object does not support this property or method)

Could anybody point out where are I am going wrong?
 




Hi,

Instead of Selection, fully quallify the reference using the word applicaiton object, the document object etc.

Did you use the CreateObject method?

Skip,

[glasses] [red][/red]
[tongue]
 
Skip is correct - of course :)

The reason for your error message, though, is that Selection, as coded, refers to the Excel Selection, which does not have a GoTo method.

Enjoy,
Tony

------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.

Professional Office Developers Association
 
Skip/Tony, thanks for responding.In answer to your question, I did use the CreateObject method:

Code:
Dim wrdApp As Word.Application
Dim wrdDoc As Word.Document
Set wrdApp = CreateObject("Word.Application")
Set wrdDoc = wrdApp.Documents.Open("C:\Test.doc")

So should I be using something along the lines of:

Code:
wrdDoc.GoTo What:=wdGoToBookmark, Name:="project"
wrdDoc.TypeText Text:="xxx"
 
Try working directly with the Range, something like ...
Code:
[blue]wrdDoc.Bookmarks("project").Range.Text="xxx"[/blue]
.. but be aware that this (as your original idea) will erase the bookmark

Enjoy,
Tony

------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.

Professional Office Developers Association
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top