none
Creating doc from template RRS feed

  • Question

  • Hi

    How can I use last binding to create a doc from a word template and fill some text at bookmarks in vb.net code?

    Thanks

    Regards

    Sunday, April 3, 2016 2:15 PM

Answers

  • Hi, Y a h y a

    Use the following code to create new word document using template and assign some value to bookmark.

    Dim oWord As Word.Application
            Dim oDoc As Word.Document
            Dim curDoc As Word.Document
            oWord = CreateObject("Word.Application")
            oWord.Visible = True
            oDoc = oWord.Documents.Add
            oWord.Documents.Add("C:\Users\Administrator\Documents\Custom Office Templates\demotemplate.dotm")
            oWord.ActiveDocument.Bookmarks.Add(Name:="newbookmark")
            curDoc = oWord.ActiveDocument
            curDoc.Bookmarks("newbookmark").Range.Text = "demo text"
    

    Regards

    Deepak



    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.

    • Marked as answer by Y a h y a Tuesday, April 5, 2016 8:51 AM
    Monday, April 4, 2016 3:29 AM
    Moderator

All replies

  • Hi, Y a h y a

    Use the following code to create new word document using template and assign some value to bookmark.

    Dim oWord As Word.Application
            Dim oDoc As Word.Document
            Dim curDoc As Word.Document
            oWord = CreateObject("Word.Application")
            oWord.Visible = True
            oDoc = oWord.Documents.Add
            oWord.Documents.Add("C:\Users\Administrator\Documents\Custom Office Templates\demotemplate.dotm")
            oWord.ActiveDocument.Bookmarks.Add(Name:="newbookmark")
            curDoc = oWord.ActiveDocument
            curDoc.Bookmarks("newbookmark").Range.Text = "demo text"
    

    Regards

    Deepak



    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.

    • Marked as answer by Y a h y a Tuesday, April 5, 2016 8:51 AM
    Monday, April 4, 2016 3:29 AM
    Moderator
  • Hi yahya,

    Use the following code to create new word document using template and assign some value to bookmark using late binding.

    Dim oWord As Word.Application
            Dim curDoc As Word.Document
            oWord = CreateObject("Word.Application")
            oWord.Visible = True
            oWord.Documents.Add("C:\Users\Administrator\Documents\Custom Office Templates\demotemplate.dotm")
            oWord.ActiveDocument.Bookmarks.Add(Name:="newbookmark")
            curDoc = oWord.ActiveDocument
            Dim myvalue As String
            myvalue = InputBox("Enter the value")
            curDoc.Bookmarks("newbookmark").Range.Text = myvalue
    

    Regards

    Deepak


    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.

    Wednesday, April 13, 2016 8:53 AM
    Moderator