+ Reply to Thread
Results 1 to 6 of 6

Using Excel Macro to Print Word Documents

  1. #1
    Mike
    Guest

    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

  2. #2
    Steve Yandl
    Guest

    Re: 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" <mjnowak@dow.com.(donotspam)> wrote in message
    news:5AE7C19C-7208-4A0F-A9A8-783107B52C11@microsoft.com...
    >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




  3. #3
    Mike
    Guest

    Re: 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" <mjnowak@dow.com.(donotspam)> wrote in message
    > news:5AE7C19C-7208-4A0F-A9A8-783107B52C11@microsoft.com...
    > >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

    >
    >
    >


  4. #4
    Mike
    Guest

    Re: 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" <mjnowak@dow.com.(donotspam)> wrote in message
    > news:5AE7C19C-7208-4A0F-A9A8-783107B52C11@microsoft.com...
    > >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

    >
    >
    >


  5. #5
    Registered User
    Join Date
    03-24-2013
    Location
    Duncan, USA
    MS-Off Ver
    Excel 2007
    Posts
    2

    Re: Using Excel Macro to Print Word Documents

    Could this be modified to do multiple hyperlinked documents as well?

  6. #6
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Using Excel Macro to Print Word Documents

    Mark,

    Unfortunately you need to post your question in a new thread, it's against the forum rules to post a question in the thread of another user. If you create your own thread, any advice will be tailored to your situation so you should include a description of what you've done and are trying to do. Also, if you feel that this thread is particularly relevant to what you are trying to do, you can surely include a link to it in your new thread.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1