Assign a DOCVARIABLE to a combo box that populates a word doc ( in Word 2010) Using VS 2012 ( RRS feed

  • Question

  • Hello  Everyone,

    This is my first time posting on this forum. I have a form that I'm able to transfer all the contents of my combo boxes on a winform to a word doc (one page) via bookmarks. The project was upgraded by my boss to include a total of 10 pages. These pages will have repetitive data from the initial form. After some searching DOCVARIABLE'S seems the way to go. I've searched this forum for over an hour. Things  that pertain to my specific goal I've found are from 2006- 2008 and certain parts of the code are incompatible with the version i'm using. Any suggestions (i've tried Greg Maxey, Doug Robbins (website) all ready) will be helpful.

    Thank you in advance


    Win 7 Enterprise

    MS Word 2010

    Visual Studio 2012

    Here's my code:

    Imports Microsoft.Office.Interop
    Public Class Form1

        Private Sub btnadd_Click(sender As Object, e As EventArgs) Handles btnadd.Click
            Dim oWord As Word.Application
            Dim oDoc As Word.Document
            oWord = CreateObject("Word.Application")
            oWord.Visible = True
            oDoc = oWord.Documents.Add("C:\Users\eharris\Documents\From Russ\WindowsApplication2\WindowsApplication2\Set up_Bookmark_Test.docx ") ' replace  path to link to word doc'

            'My Combo Data to String'
            Dim ProgData As String
            Dim MtlData As String
            Dim VrctData As String
            Dim MachData As String
            Dim DatepData As String

            ' Import This Data to Bookmark'
            DatepData = Format(Me.DateTimePicker1.Value, "MM/dd/yyyy")
            ProgData = CBProgmr.Text
            MtlData = CBMtl.Text
            VrctData = CBVrct.Text
            MachData = CBMach.Text
            ' Go to the bookmark.'
            With oDoc.Bookmarks
                .Item("bm_MatName").Range.Text = MtlData
                .Item("bm_PrgName").Range.Text = ProgData
                .Item("bm_VrctName").Range.Text = VrctData
                .Item("bm_MachName").Range.Text = MachData
                .Item("bm_DatePname").Range.Text = DatepData
            End With

        End Sub

        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        End Sub
    End Class

    Tuesday, March 31, 2015 10:53 PM

All replies

  • Hi Wadedigi,

    It's a good idea to use docvariable in the Word documents or templates. For how to programmatically store value into it, please take a look at this KB article:

    How to store and retrieve variables in Word documents

    But bookmarks can still be used in this case.

    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.

    Tuesday, April 7, 2015 6:19 AM