Consulting

Results 1 to 5 of 5

Thread: Populating Word Bookmarks without deleting it

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1

    Populating Word Bookmarks without deleting it

    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
    Last edited by Paul_Hossler; 10-17-2017 at 06:53 AM. Reason: Added CODE Tags

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •