Open WORD doc from EXCEL using VBA

G

Guest

Working in Office 2003, I have information in an EXCEL file which I can
mailmerge manually into a WORD doc.
I would like to automate this process from a button in the EXCEL file to ask
the user if he wants to view the mailmerged WORD doc. which then goes on to
carry out the mailmerge and display the final result in WORD.
If I want to give the option to print out the WORD doc, does this have to be
part of the EXCEL or the WORD macro?
Any help appreciated.
Yendorian
 
N

Norman Yuan

If you can write VBA code, it can be done on either sides: in Word, or in
Excel.

From Excel side:

1. Set Reference to Work Object Library in VBA IDE;
2. Start Word and open certain doc file:

Dim wd AS Word.Application
Dim doc As Word.Document
Set wd=New Word.Application
wd.Visibale=True
Set doc=wd.Documents.Open("C:\MyPath\MyDoc.doc)
'do soemthing with the opened document, such as grab data from current
worksheet to update filed/bookmark on document
'Print the doc...
doc.Close True
wd.Quit

From Word side:

1. Set reference to Excel Object Library
2. Start Excel and open certain workbook

Dim xls as Excel.Application
Dim wb As WorkBook
Dim sh As Worksheet

Set xls=New Excel.Application
xls.Visible=True
Set wb=xls.Workbooks.Open("....")
Set sh=wb.Sheet(1) 'Assume the first sheet has needed data
'Get data from the cells on the sheet,
'Update existing doc's field/bookmark
'Print the doc, if needed
Set sh=Nothing
wk.Close Flase
xls.Quit

With latter, you can even get data from Worksheet by using ADO without open
Excel, this makes your code run quicker.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top