Excel VBA - Fill Multiple Word Bookmarks with one cell value

Storm8585

New Member
Joined
Sep 5, 2014
Messages
47
Hi,
I have a Word document with lots of references to a Project No. (and others). I use VBA to auto-fill these in from a spreadsheet. Because Word makes you give each bookmark a unique name I have lots of bookmarks relating to the same cell value in my worksheet. This makes my code long an inefficient. Currently I am using the method

Code:
With objWord
    .Bookmarks("PNo1").Range.Text = Range("AA30").Value
    .Bookmarks("PNo2").Range.Text = Range("AA30").Value
    .Bookmarks("PNo3").Range.Text = Range("AA30").Value
End With
and so on.... Is there a way I can say something like .Bookmarks("PNo1","PNo2","PNo3") etc??

Thanks in advance
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Unless you have a situation in which you might need to give some of the bookmarks a different value, you could use just one bookmark and, in the Word document, have as many pre-existing cross-references to it as you need, scattered throughout the body of the document. Then all you need is code like:
Code:
Dim BmkRng As Object
Const BmkNm As String = "SomeBookmarkName"
With objWord
  If .Bookmarks.Exists(BmkNm) Then
    Set BmkRng = .Bookmarks(BmkNm).Range
    BmkRng.Text = Range("AA30").Value
    .Bookmarks.Add BmkNm, BmkRng
  Else
    MsgBox "Bookmark: " & BmkNm & " not found."
  End If
  .Fields.Update
End With
Set BmkRng = Nothing
 
Upvote 0

Forum statistics

Threads
1,214,948
Messages
6,122,420
Members
449,083
Latest member
Ava19

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top