![]() |
Using Excel Macro to Print Word Documents
I am trying to set up a macro to print an Excel document. This was easy
enough but the Excel document has links to word documents that display the visuals that accompany the Excel text. The macro will need to Print the word documents with the Excel spread sheet. My current macro stops as soon as word is opened as if there is no communication link between Excel and Word. I basically just need the macro (in Excel) to open, print, and close a word document. Any ideas? Help! -- Michael J. Nowak Energy Systems/Dow Chemical Texas City, TX |
Using Excel Macro to Print Word Documents
Mike,
With your VBE window open, click 'Tools References' and put a check by "Microsoft Word 11.0 Object library" (note, it may not be 11.0 if you have a different version of Office than me) The example below opens Word if it wasn't already open, opens and prints the document "C:\Scripts\Test1.doc", closes the document and if Word wasn't open in advance it closes the Word application. You may want to change the line that makes the Word application visible so you don't see the window flash but this version will give you a sense of the timing. _____________________________________ Sub PrintWordDoc() Dim bStarted As Boolean Dim oApp As Word.Application On Error Resume Next Set oApp = GetObject(, "Word.Application") 'Get the running instance of Word, if there is no instance 'create a new one: If Err < 0 Then bStarted = True Set oApp = CreateObject("Word.Application") End If oApp.Activate oApp.Visible = True oApp.Documents.Open ("C:\Scripts\Test1.doc") oApp.PrintOut oApp.ActiveDocument.Close wdDoNotSaveChanges 'Quit only when Word was not running when we started this code If bStarted Then oApp.Quit End If Set oApp = Nothing End Sub _______________________________________ Steve "Mike" .(donotspam) wrote in message ... I am trying to set up a macro to print an Excel document. This was easy enough but the Excel document has links to word documents that display the visuals that accompany the Excel text. The macro will need to Print the word documents with the Excel spread sheet. My current macro stops as soon as word is opened as if there is no communication link between Excel and Word. I basically just need the macro (in Excel) to open, print, and close a word document. Any ideas? Help! -- Michael J. Nowak Energy Systems/Dow Chemical Texas City, TX |
Using Excel Macro to Print Word Documents
Thanks a bunch, Steve. That worked. I really appreciate your help. Hope
you had a good weekend, -- Michael J. Nowak Energy Systems/Dow Chemical Texas City, TX "Steve Yandl" wrote: Mike, With your VBE window open, click 'Tools References' and put a check by "Microsoft Word 11.0 Object library" (note, it may not be 11.0 if you have a different version of Office than me) The example below opens Word if it wasn't already open, opens and prints the document "C:\Scripts\Test1.doc", closes the document and if Word wasn't open in advance it closes the Word application. You may want to change the line that makes the Word application visible so you don't see the window flash but this version will give you a sense of the timing. _____________________________________ Sub PrintWordDoc() Dim bStarted As Boolean Dim oApp As Word.Application On Error Resume Next Set oApp = GetObject(, "Word.Application") 'Get the running instance of Word, if there is no instance 'create a new one: If Err < 0 Then bStarted = True Set oApp = CreateObject("Word.Application") End If oApp.Activate oApp.Visible = True oApp.Documents.Open ("C:\Scripts\Test1.doc") oApp.PrintOut oApp.ActiveDocument.Close wdDoNotSaveChanges 'Quit only when Word was not running when we started this code If bStarted Then oApp.Quit End If Set oApp = Nothing End Sub _______________________________________ Steve "Mike" .(donotspam) wrote in message ... I am trying to set up a macro to print an Excel document. This was easy enough but the Excel document has links to word documents that display the visuals that accompany the Excel text. The macro will need to Print the word documents with the Excel spread sheet. My current macro stops as soon as word is opened as if there is no communication link between Excel and Word. I basically just need the macro (in Excel) to open, print, and close a word document. Any ideas? Help! -- Michael J. Nowak Energy Systems/Dow Chemical Texas City, TX |
All times are GMT +1. The time now is 10:39 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com