PDA

View Full Version : How to iterate over all bookmarks in a word document



ZKirk
11-13-2012, 12:46 AM
I've got this function:

Public Sub WB(ByVal bkName As String, ByVal bkText As String)
Dim r As Range
Set r = ActiveDocument.Bookmarks(bkName).Range
r.Text = bkText
ActiveDocument.Bookmarks.Add bkName, r
End Sub

That I use to apply values to bookmarks in my document. How can I iterate over all bookmarks and return there values to None/"" ?

gmaxey
11-13-2012, 09:08 AM
Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey
Dim oBM As Bookmark
Dim lngCount As Long
For lngCount = 1 To ActiveDocument.Bookmarks.Count
Set oBM = ActiveDocument.Bookmarks(lngCount)
WB oBM.Name, ""
Next lngCount
End Sub
Public Sub WB(ByVal bkName As String, ByVal bkText As String)
Dim r As Range
Set r = ActiveDocument.Bookmarks(bkName).Range
r.Text = bkText
ActiveDocument.Bookmarks.Add bkName, r
End Sub

ZKirk
11-13-2012, 09:36 AM
Awesome, thank you very much.