MS Word 2007 - values assignment to bookmarks

HaiderAliKhan

New Member
Joined
Mar 27, 2014
Messages
2
Hello All,I am a newbie in MS-Word and need to find a way to access a given number of pre-defined bookmarks in a word-2007 document and assign values to their text property.Eg.How we access ranges in MS-Excel,Thisworkbook.sheets("sheet1").range("A1:C1").value = Array("Name","Age","Gender")So, what i actually need is my range in word would be bookmark1,bookmark2 etc. that i want to assign values to.Can we do it in a single statement as in excel like...Wrddoc.range(worddoc.bookmarks("bm1").range,worddoc.bookmarks("bm2").range).value = array("variable1","variable2")
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Word doesn't work that way. You need to loop through your array, populating each bookmark's range individually, using code like:

Code:
Sub Demo()
Application.ScreenUpdating = False
Dim i As Long, ArrData, ArrBkMks
ArrData = Array("Name", "Age", "Gender")
ArrBkMks = Array("Bm1", "Bm2", "Bm3")
For i = 0 To UBound(ArrData)
  Call UpdateBookmark(ArrData(i), ArrBkMks(i))
Next
Application.ScreenUpdating = True
End Sub

Sub UpdateBookmark(StrBkMk As String, StrTxt As String)
Dim BkMkRng As Range
With ActiveDocument
  If .Bookmarks.Exists(StrBkMk) Then
    Set BkMkRng = .Bookmarks(StrBkMk).Range
    BkMkRng.Text = StrTxt
    .Bookmarks.Add StrBkMk, BkMkRng
  End If
End With
Set BkMkRng = Nothing
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,029
Messages
6,122,757
Members
449,094
Latest member
dsharae57

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