Reputation: 115
I am fairly new so please excuse my ignorance.. I want to format bookmark (Rich Text Content Control).
I have the following code to do that
ActiveDocument.Bookmarks("ALTERNATIVE").Range.Font.TextColor = back
more formatting to text
My question is how can I do that efficiently? Is there a way to select multiple bookmarks or select all Rich Text Content Control to do the format on all of them in the same code?
Upvotes: 1
Views: 532
Reputation: 4221
Depending on your needs you could use either approach:
Loop through the Content controls to update the formatting:
For Each oContentControl In ActiveDocument.ContentControls
oContentControl.Range.Font.Color = RGB(255, 0, 0) 'Red
Next
Loop through all the bookmarks to achieve the same result:
For Each bookmark In ActiveDocument.Bookmarks
bookmark.Range.Font.Color = RGB(255, 0, 0) 'Red
Next
EDIT
As per request, below is how to fine tune the above loop for content controls of a certain type (MSDN Link for types).
1.a Loop through all richText content controls to update the formatting:
For Each oContentControl In ActiveDocument.ContentControls
If oContentControl .Type = wdContentControlRichText Then
oContentControl.Range.Font.Color = RGB(255, 0, 0) 'Red
End If
Next
Upvotes: 1
Reputation: 14383
Perhaps something like this might do?
Dim Bmk As Bookmark
For Each Bmk In ActiveDocument.Bookmarks
Debug.Print Bmk.Range.Font.TextColor
Next Bmk
Upvotes: 1