简体   繁体   English

使用VBA从MS Word打开Excel文档

[英]Open an Excel document from MS Word Using VBA

I want to open a Excel sheet through Word VBA, paste information from the Word document row wise and save it. 我想通过Word VBA打开Excel工作表,明智地将Word文档行中的信息粘贴并保存。 I have code for picking up specific information from the Word document but do not know how to open Excel and save it. 我有用于从Word文档中提取特定信息的代码,但不知道如何打开Excel并保存它。

I have found a solution in the following site: http://www.exceltip.com/st/Control_Excel_from_Word_using_VBA_in_Microsoft_Excel/463.html 我在以下站点中找到了解决方案: http : //www.exceltip.com/st/Control_Excel_from_Word_using_VBA_in_Microsoft_Excel/463.html

It is giving an error and also I do not know how to add a reference to the Excel library in Word. 它给出了一个错误,并且我也不知道如何在Word中添加对Excel库的引用。

Error: Dim xlApp As Excel.Application - Compile Error "User defined type not defined" 错误:Dim xlApp作为Excel.Application-编译错误“未定义用户定义的类型”

You could do one of two things here -- 您可以在这里做两件事之一-

1) Change "Excel.Application" and "Excel.Workbook" to "Object" (late bound) 1)将“ Excel.Application”和“ Excel.Workbook”更改为“对象”(后期绑定)

or 要么

2) In the VBA Editor, go to Tools > References and look for "Microsoft Excel x.0 Object Library" and check the checkbox. 2)在VBA编辑器中,转到“工具”>“引用”,然后查找“ Microsoft Excel x.0对象库”,然后选中该复选框。 (early bound) (早起)

The 'x' depends on your Excel version. “ x”取决于您的Excel版本。 11.0 is Office 2003, 12.0 is Office 2007, and so on. 11.0是Office 2003,12.0是Office 2007,依此类推。

Your exceltip link seems to be bad, so it's impossible to know what other changes might be needed if you move to late binding; 您的exceltip链接似乎是错误的,因此,如果您后期进行绑定,则无法知道还需要进行哪些其他更改; setting a VBA reference to the Excel Object library would be the simplest solution. 将VBA引用设置为Excel对象库将是最简单的解决方案。 For an implementation on StackOverflow that you might adapt, see: VBA code that copies tables from multiple Word files to separate worksheets in excel Excel, naming the worksheet the name of the Word doc? 有关您可能会适应的StackOverflow的实现,请参阅: VBA代码可将表格从多个Word文件复制到excel Excel中的单独工作表,并在工作表中命名Word文档的名称?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM