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

Preventing bookmark from being deleted upon changing .Range.Text??

Status
Not open for further replies.

ramgni

Technical User
Feb 11, 2002
6
DE
Hi,
I am trying to set up a structured document in Word2000, consisting of many sections, each containing various information that can change at the users command from an external VB6 program (reporting system).
In order to be able to move sections and to access the elements of a section (legend, comment, figures, etc.) I add bookmarks to the document for all sections (and subsection) which then get filled with the information.

However, when I select a bookmark's full range and then change the text or whatever to something else with the code below, the text is changed, but afterwards the bookmark is gone.

Set CurrRange = CurrDoc.Bookmarks("BookName").Range
CurrRange.Text = "Something else..."
... Bookmark gone

The only way I seem to be able to save the bookmark from being deleted when changing its content is to leave one character at the end deselected when building the range.

Set CurrRange = CurrDocument.Range(Start:=CurrDocument.Bookmarks("BookName").Range.Start, End:=CurrDocument.Bookmarks("BookName").Range.End - 1)

This means always having one extra character at the end of the bookmark - and I simply can not imagine that this should be the only way to preserve the bookmarks throughout changes of their content.

Can anyone help???

TIA,
Ingmar
 
Ingmar,

Try the following:


Code:
Sub DoSomethingAtBookmark()

Dim CurrRange As Range
Dim BookmarkName As String

With CurrDoc.Bookmarks("BookName")
  Set CurrRange = .Range
  BookmarkName = .Name
End With
CurrRange.Text = "Something else..."
CurrDoc.Bookmarks.Add Name:=BookmarkName, Range:=CurrRange

End Sub


HTH

M. Smith
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top