从Word到Excel中的内容控件提取数据 [英] Extract data from content controls in Word to Excel

查看:1551
本文介绍了从Word到Excel中的内容控件提取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个form-fillable的Word文档,即它有内容控件对象,如富文本和日期选择器内容控件。我正在寻找将特定字段的数据提取到Excel中。例如,每个表单都有项目标题,开始日期和经理。我想用这三个数据的1行表格。最终,这几个月将需要为数百种形式进行,但现在我只想从头开始。

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 from specific fields into Excel. For example, every form has the project title, start date, and manager. I would like 1 row for that form with those three pieces of data. Eventually this will need to be done for a few hundred of these forms every few months, but for now I'd like to just start with one.

我设想有一个按钮,将运行VBA代码从Word文档中拉取数据,并填充表格中的正确单元格。使用Word文档的文件路径由用户指定。

I envision having a button on the Excel sheet that will run VBA code to pull the data from the Word document, and populate the proper cells in the sheet. With the filepath for the Word doc being specified by the user.

我是VBA的新手。如何将我的代码指向正确的文件,然后再在我需要的特定字段?我在Word文档中提供字段标题?

I am new to VBA. How do I point my code at the right file, and then again at the specific field I need? Do I give the fields titles in the Word doc?

这是在MS Office '13

This is in MS Office '13

推荐答案

您的应用程序将具有大量具体细节,这些细节难以解决,无需具体细节。要开始,这里有一些非常简单的代码从Word中的Excel中下拉列表中获取日期。

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.

注意使用Word,您需要创建一个在Excel方面引用Microsoft Word 15.0对象库。工具 - > VBA编辑器中的参考。

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.

当跨应用程序工作时,可以帮助您在Word中编写VBA,然后在您拥有所需属性后将其移动到Excel。

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.

这个VBA的Excel方程式:

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

我的Word文件包含一个ContentControl 。不知道你如何处理你想要的(试错?)。

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

Excel边将日期放在正确的位置。

The Excel side drops the date in the right place.

这篇关于从Word到Excel中的内容控件提取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆