![]() |
Open WORD doc from EXCEL using VBA
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 |
Open WORD doc from EXCEL using VBA
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. "Yendorian" wrote in message ... 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 |
All times are GMT +1. The time now is 05:09 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com