Hi guys,
I am trying to populate a word bookmark through vba in excel, however my current code deletes the bookmark.
I want to populate the bookmark and save the file. Once I do, I want to populate it with a different value and save it as a different file. When using my current code, after populating for the first time, it gives me an error saying that the bookmark does not exist. I guess it is deleting the bookmark once it is populated.
Would appreciate if you guys could also help me out with the code for saving the file right after it populates the bookmark.
Sub CartaModelo()
Dim wApp As Word.Application
Dim bmrange As Range
n = Cells(1, 2).End(xlDown).Row
Set wApp = CreateObject("Word.Application")
With wApp
.Visible = True
.Documents.Open ("C:\Users\3177475\Documents\PIS e Cofins\Carta Modelo\Carta Modelo v4.docx")
For i = 2 To n
.Selection.Goto What:=wdGoToBookmark, Name:="Valor"
.Selection.TypeText Text:=Cells(i, 2).Value
Next i
End With
End Sub