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

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
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,215,453
Messages
6,124,925
Members
449,195
Latest member
Stevenciu

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