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

Word Bookmark properties

Status
Not open for further replies.

MP498T

MIS
Mar 14, 2001
15
GB
I have a little experience of VBA (from Excel) but I'm struggling with a Word 97 issue and properties of a Bookmark.

I want to be able to change the Text found at a known Bookmark (called "Doc_Ref") from "Initial Text" to some text the user types in.

What I'm trying for is as follows, the InputBox bit is okay it's the next line that doesn't work.
Code:
Sub ...
 strNewText = InputBox("Enter Document Ref")
 Documents("Test_Doc").Bookmarks("Doc_Ref").Value = strNewText
End Sub
I've also tried
Code:
Documents("Test_Doc").Bookmarks("Doc_Ref").Text = strNewText
So can anyone tell me what the property of the Document / Bookmark is that I change to alter the text pleas

TIA
Jason

 
Bookmarks("Doc_ref").Range ?

Ingrid
 
Bookmarks are just positions in the document. To insert text at a bookmark:

<bookmark>.Range.InsertAfter <new text value>

M :)
 
Changing Bookmarks(&quot;Doc_ref&quot;).Range got us close to what we wanted i.e. replacing the 'initial text' at the bookmark, however there was a draw back, as it lost the Bookmark Name so no longer worked as a bookmark.

The idea to insert worked except the 'new text' we inserted wasn't part of the bookmark, it came after - the square brackets - as just text. So when removing the 'initial text' at the bookmark the bookmark was empty.

We have got around it by what seems a roundabout way but it works and that's what counts in the end.

What we did was to find the Bookmark, delete it and at the same position insert the 'new text' and convert it become the Bookmark we previously deleted.

Thank you both for your replies, they got us there . :)

Jason.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top