Extract data from content controls in Word to Excel

≡放荡痞女 提交于 2019-12-02 03:50:51

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.

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?).

The Excel side drops the date in the right place.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!