0
votes

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"

2

2 Answers

1
votes

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.

0
votes

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?