none
Word Template filling with VB RRS feed

  • Question

  • i'm new to office development and want to create a simple application that :

    opens a word 2007-2010-2013 template. read each and every placeholder. fill in each one with the appropriate data.

    however, how can i create a placeholder in a word template ? how can i list placeholders and fill in them usin VB 2013 ?

    thank you

    Saturday, September 6, 2014 3:38 PM

Answers

All replies

  • Hi abinn,

    Welcome to MSDN forum.

    Please refer to How to: Programmatically Update Bookmark Text.

    In addition, this article below contains VBA code, it is similar with VB.NET:

    Working with Content Controls

    Regards,

    George.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, September 8, 2014 9:04 AM
    Moderator
  • Hi Abinn,

    If you do not mind to use a third part component, you can consider Aceoffix which can open template on line or lan, and you can fill data into the template automatically.

    Tuesday, January 5, 2016 6:19 AM
  • I think you should see this link.

    http://gregmaxey.mvps.org/word_tip_pages/master_your_formfields.html

    Now, after you've added some forms to your word file, run the following VBA script, from Excel.

    DocVariables

    Sub PushToWord()
    
    Dim objWord As New Word.Application
    Dim doc As Word.Document
    Dim bkmk As Word.Bookmark
    sWdFileName = Application.GetOpenFilename(, , , , False)
    Set doc = objWord.Documents.Open(sWdFileName)
    'On Error Resume Next
    
    objWord.ActiveDocument.variables("BrokerFirstName").Value = Range("BrokerFirstName").Value
    objWord.ActiveDocument.variables("BrokerLastName").Value = Range("BrokerLastName").Value
    objWord.ActiveDocument.variables("Ryan").Value = Range("Ryan").Value
    
    
    objWord.ActiveDocument.Fields.Update
    
    'On Error Resume Next
    objWord.Visible = True
    
    End Sub
    
    

    BookMarks

    Sub PushToWord()
    
    Dim objWord As New Word.Application
    Dim doc As Word.Document
    Dim bkmk As Word.Bookmark
    sWdFileName = Application.GetOpenFilename(, , , , False)
    Set doc = objWord.Documents.Open(sWdFileName)
    On Error Resume Next
    
        ActiveDocument.Variables("BrokerFirstName").Value = Range("B1").Value
        ActiveDocument.Variables("BrokerLastName").Value = Range("B2").Value
        ActiveDocument.Fields.Update
    
    On Error Resume Next
    objWord.Visible = True
    
    End Sub
    
    


    Knowledge is the only thing that I can give you, and still retain, and we are both better off for it.

    Thursday, January 7, 2016 2:52 AM