Extract data from content controls in Word to Excel

后端 未结 1 338
鱼传尺愫
鱼传尺愫 2021-01-24 13:09

I have a Word document that is \"form-fillable\", i.e. it has content control objects in it such as rich text and date picker content controls. I am looking to extract the data

相关标签:
1条回答
  • 2021-01-24 13:58

    Your application is going to have a large number of specific details which are difficult to address without the specifics. To get started, here is some very simple code to get the Date from a drop-down in Excel from Word.

    Note to work with Word, you need to create a reference to "Microsoft Word 15.0 Object Library" on the Excel side. Tools -> References in the VBA Editor.

    reference addition

    When working across applications, it can help to write the VBA in Word and then move it over to Excel once you have the properties you want.

    This VBA for the Excel side of the equation:

    Sub GetDataFromWordFile()
    
        Dim wrd As Word.Application
        Dim file As Word.Document
    
    
        Set wrd = New Word.Application
        Set file = wrd.Documents.Open("test.docx")
    
        Range("A1") = file.ContentControls(1).Range.Text
    
        file.Close
        wrd.Quit
    
    End Sub
    

    My Word file includes a single ContentControl. Not sure how you address the ones you want (trial and error?).

    Word file

    The Excel side drops the date in the right place.

    Excel side

    0 讨论(0)
提交回复
热议问题