简体   繁体   中英

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. I have code for picking up specific information from the Word document but do not know how to open Excel and save it.

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

It is giving an error and also I do not know how to add a reference to the Excel library in Word.

Error: Dim xlApp As Excel.Application - Compile Error "User defined type not defined"

You could do one of two things here --

1) Change "Excel.Application" and "Excel.Workbook" to "Object" (late bound)

or

2) In the VBA Editor, go to Tools > References and look for "Microsoft Excel x.0 Object Library" and check the checkbox. (early bound)

The 'x' depends on your Excel version. 11.0 is Office 2003, 12.0 is Office 2007, and so on.

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; setting a VBA reference to the Excel Object library would be the simplest solution. 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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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