Vba – Open an Excel document from MS Word Using VBA

ms-wordvba

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"

Best Answer

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.

Related Topic