PDA

View Full Version : Solved: Clearing bookmarks in Word



Dragon71
03-18-2009, 12:53 PM
Chasing code that will clear only selected bookmarks in Word
Have tried =Null and .Bookmarks("Client").Range.Text = "",but neither seem to work
Bookmarks entered using below

Private Sub cmdOK_Click()
With ActiveDocument
.Bookmarks("Job 1").Range.Text = ListBox1.Value
.Bookmarks("Job 2").Range.Text = TextBox1.Value
.Bookmarks("Job 3").Range.Text = ListBox3.Value
.Bookmarks("Job 4").Range.Text = ListBox4.Value
.Bookmarks("Job 5").Range.Text = ListBox5.Value
.Bookmarks("Job 6").Range.Text = ListBox6.Value
.Bookmarks("Job 7").Range.Text = ListBox7.Value
.Bookmarks("Job 8").Range.Text = ListBox8.Value
.Bookmarks("Job 9").Range.Text = TextBox2.Value
.Bookmarks("inspectiondate").Range.Text = TextBox3.Value
.Bookmarks("pulleynumber").Range.Text = TextBox4.Value

End With
End Sub



There is another post on here regarding this subject from Nick,but i could not work out the answer from the responses

Please help
Only want to clear specific bookmarks,not all on the whole page
:banghead:
Thanks

lucas
03-18-2009, 03:48 PM
Maybe something like this:

for your button code. It calls the function fillabookmark with the first parameter as the bookmark name and the second is the text you want in it:
Private Sub CommandButton1_Click()
Call FillABookmark("job1", "Test")
End Sub
Private Sub CommandButton2_Click()
Call FillABookmark("job1", "")
End Sub


In a standard module:
It's a sub but it serves as a function for handling multiple bookmarks. Thanks to Gerry for sharing it with us.
Sub FillABookmark(strBM_Name As String, strBM_Text As String)
With Selection
.GoTo what:=wdGoToBookmark, Name:=strBM_Name
.Collapse Direction:=wdCollapseEnd
ActiveDocument.Bookmarks(strBM_Name).Range.Text = strBM_Text
.MoveEnd unit:=wdCharacter, Count:=Len(strBM_Text)
ActiveDocument.Bookmarks.Add Name:=strBM_Name, Range:=Selection.Range
.Collapse Direction:=wdCollapseEnd
End With
End Sub

One other thing that you have that I don't understand it that you show your bookmarks to be things like Job 1 with a space......I don't think that will work.

see attached.

Dragon71
03-18-2009, 03:59 PM
Lucas

Only used "Job1" as an example,had peoples names etc in there,so for public reasons took them out
Will try you reply though and let you know

Thanks for the help and i will see if it works

Dragon71
03-18-2009, 04:51 PM
Works well
Thanks Lucas and Gerry you have saved me some hair

:bow: