none
VBA word 2010 RRS feed

  • Question

  • Hello all,

    I hope one of you geniuses can help with a problem; I’m a beginner in coding and thank you in advance for any feedback.

    What I want to do is capture certain word property that hold some unique ID’s  that are inserted by our DMS (document management system), once captured after the user save the document these properties captured will be used to run a merge data script that will import data onto the document.

    I’m using word 2010 in winnows 7 environment, the current vba macro are run from out norml.dot.

    Appreciate any help.

    Friday, March 29, 2013 12:18 PM

All replies

  • i found the following code that returns the document properties, what i would like to do is show these properties in a form view so it can passed to another code that would merge the data.

    Option Explicit

    Sub PropsToTable()
    Dim oRange As Word.Range
    Dim oProp  As DocumentProperty
    Dim sTmp   As String

     '\\ value for table header
     sTmp = "Property Name" & vbTab & "Property Value"

     '\\ To continue if a document property has no value set
      On Error Resume Next
      
      '\\ Loop document properties and build tab delimeted string
      For Each oProp In ActiveDocument.BuiltInDocumentProperties
          sTmp = sTmp & vbTab & oProp.Name & vbTab & oProp.Value
      Next
        
      '\\ Set reference to start of document (range)
      Set oRange = ActiveDocument.Range(0, 0)
      
      '\\ Insert the string and covert it to a table
        With oRange
            .InsertAfter Text:=sTmp
            .ConvertToTable Separator:=wdSeparateByTabs, _
                            NumColumns:=2, _
                            AutoFit:=True
        End With

     'Clean up
     Set oRange = Nothing
    End Sub


    roufghrier

    Friday, March 29, 2013 12:53 PM
  • <<what i would like to do is show these properties in a form view so it can passed to another code that would merge the data>>

    I don't understand what you mean with this.

    1. Please be more specific about what you mean by a "form view"

    2. I don't understand how the "form view" is meant to pass "it" to another code, please elaborate


    Cindy Meister, VSTO/Word MVP, my blog

    Saturday, March 30, 2013 6:42 AM
    Moderator