I found this post message 3566 by Macropod advising this macro deletes a bookmark when the value is ‘0’, but when the value is ‘1’ can you then insert a name & address for example into that said bookmark in the same macro?
E.g. .Bookmarks (“Name”).Range.Text=ws.Range(“B2”).Value
Sub CreateWordDocument()
'Note: This code requires a VBA reference to Word, via Tools|References
Dim xlSht As Worksheet, wdApp As New Word.Application, wdDoc As Word.Document, lRow As Long, r As Long
Set xlSht = ActiveSheet: lRow = xlSht.UsedRange.Cells.SpecialCells(xlCellTypeLastCell).Row
With wdApp
'Show the Word session
.Visible = True
' create a new Word Document based on the specified template
Set wdDoc = .Documents.Add("C:\MyTemplate.dotm")
With wdDoc
'loop through used range and process the corresponding Word bookmarks
For r = 1 To lRow
If .Bookmarks.Exists(xlSht.Range("A" & r).Text) Then
'Erase designated bookmark content
If xlSht.Range("B" & r).Value = 0 Then
.Bookmarks(xlSht.Range("A" & r).Text).Range.Text = vbNullString
End If
End If
Next
End With
.Activate
End With
'MEMORY CLEANUP
Set wdDoc = Nothing: Set wdApp = Nothing: Set xlSht = Nothing
End Sub
E.g. .Bookmarks (“Name”).Range.Text=ws.Range(“B2”).Value
Sub CreateWordDocument()
'Note: This code requires a VBA reference to Word, via Tools|References
Dim xlSht As Worksheet, wdApp As New Word.Application, wdDoc As Word.Document, lRow As Long, r As Long
Set xlSht = ActiveSheet: lRow = xlSht.UsedRange.Cells.SpecialCells(xlCellTypeLastCell).Row
With wdApp
'Show the Word session
.Visible = True
' create a new Word Document based on the specified template
Set wdDoc = .Documents.Add("C:\MyTemplate.dotm")
With wdDoc
'loop through used range and process the corresponding Word bookmarks
For r = 1 To lRow
If .Bookmarks.Exists(xlSht.Range("A" & r).Text) Then
'Erase designated bookmark content
If xlSht.Range("B" & r).Value = 0 Then
.Bookmarks(xlSht.Range("A" & r).Text).Range.Text = vbNullString
End If
End If
Next
End With
.Activate
End With
'MEMORY CLEANUP
Set wdDoc = Nothing: Set wdApp = Nothing: Set xlSht = Nothing
End Sub