N
Nick Curl
I have a Word doc with bookmarks and a VB app that opens and closes the doc.
With the doc open, I can use the cmdopen sub (below) to update a bookmark's
text. The text changes and bookmark remains intact (braces are displayed). I
close the doc with cmdclose sub (below) and then execute cmdopen. The doc
opens showing bookmarks and changes intact. When I update the bookmark this
time, the text changes but the bookmark is destroyed (braces removed). Any
idea why the second opening destroys the bookmark when it's text is updated?
I have a VB app with the following code:
Dim wdApp As Word.Application
Dim doc As Word.Document
Private Sub cmdopen_Click()
Dim req As String
Dim rngRange As Word.Range
Set wdApp = New Word.Application
wdApp.Visible = True
Set doc = wdApp.Documents.Open("c:/mystuff/reqman/test.doc")
req = InputBox("enter req")
Set rngRange = doc.Bookmarks(req).Range
With rngRange
.Text = "test"
.Select
End With
doc.Bookmarks.Add req, Selection.Range
Set rngRange = Nothing
End Sub
Private Sub cmdclose_Click()
doc.Close
wdApp.Quit
Set doc = Nothing
Set wdApp = Nothing
End Sub
With the doc open, I can use the cmdopen sub (below) to update a bookmark's
text. The text changes and bookmark remains intact (braces are displayed). I
close the doc with cmdclose sub (below) and then execute cmdopen. The doc
opens showing bookmarks and changes intact. When I update the bookmark this
time, the text changes but the bookmark is destroyed (braces removed). Any
idea why the second opening destroys the bookmark when it's text is updated?
I have a VB app with the following code:
Dim wdApp As Word.Application
Dim doc As Word.Document
Private Sub cmdopen_Click()
Dim req As String
Dim rngRange As Word.Range
Set wdApp = New Word.Application
wdApp.Visible = True
Set doc = wdApp.Documents.Open("c:/mystuff/reqman/test.doc")
req = InputBox("enter req")
Set rngRange = doc.Bookmarks(req).Range
With rngRange
.Text = "test"
.Select
End With
doc.Bookmarks.Add req, Selection.Range
Set rngRange = Nothing
End Sub
Private Sub cmdclose_Click()
doc.Close
wdApp.Quit
Set doc = Nothing
Set wdApp = Nothing
End Sub