Word Macro to Print Multiple Documents

FozzieBeara

New Member
Joined
May 12, 2011
Messages
3
Hello:

I have cobbled together a Word Macro that I wish to use to print multiple Word email attachments that I have downloaded and opened in multiple active windows (I say "cobbled" because I really don't know how to write VBA code other than by cutting and pasting from things I've found on the web. :oops:)

The macro works perfectly until after the last document has been printed and closed wherein I get the following error: "Run-time error '4605': This method or property is not available because a document window is not active." And then what ends up getting highlighted by the Word debugger is the second "Application.PrintOut" command lines...which confuses me. (I bolded the part where the debugger says there is an error.)

So, I was wondering if anyone would be able to offer some assistance with this...(also, if there's a way to turn off the "This document has track changes. Do you still want to print" etc. and other track-changes related prompts). Also, if you can recommend any specific books/websites that would provide more of an over-view and comprehensive understanding of VBA as it relates to Word that would also be very helpful.

Thanks in advance!

Sub PrintMultipleEmailAttachments()

Application.PrintOut fileName:="", Range:=wdPrintAllDocument, Item:=wdPrintDocumentContent, Copies:=1, Pages:="", PageType:=wdPrintAllPages, _
Collate:=True, Background:=False
ActiveDocument.Close SaveChanges:=False
Do While intCounter < 500 (**I just choose an arbitrary number of 500 so that it wouldn't stop in the middle if I had an excessive number of downloaded documents to print)
intCounter = intCounter + 1
Application.PrintOut fileName:="", Range:=wdPrintAllDocument, Item:=wdPrintDocumentContent, Copies:=1, Pages:="", PageType:=wdPrintAllPages, _
Collate:=True, Background:=False

ActiveDocument.Close SaveChanges:=False
Loop
End Sub
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Hi FozzieBeara,

Try:
Code:
Sub PrintMultipleEmailAttachments()
Dim i As Long
With Application
  For i = 1 To .Documents.Count
    .PrintOut FileName:=.Documents(i), Range:=wdPrintAllDocument, Item:=wdPrintDocumentContent, _
      Copies:=1, Pages:="", PageType:=wdPrintAllPages, Collate:=True, Background:=True
   If .Documents(i) <> ThisDocument Then .Documents(i).Close SaveChanges:=False
  Next
End With
End Sub
 
Upvote 0
Hey Macropod-

Thanks for the reply. I tried your macro but it didn't work. I got a "Run-time Error '13': Type mismatch" error immediately when I tried to run the macro and no documents actually printed.

I don't know if either of these things make a difference but
1) I am using a MacBook Pro and Microsoft Word for Mac 2011, Version 14.0.2.
2) All of these Word documents to be printed have been downloaded from an email and opened as cascading open 'Active Windows' in Word.
 
Upvote 0
Hi FozzieBeara,

Sorry, I didn't really test the code before. Try it this way:

Code:
Sub PrintMultipleEmailAttachments()
Dim Doc As Document
With Application
  For Each Doc In .Documents
    If Doc <> ThisDocument Then
      .PrintOut FileName:=Doc.FullName, Range:=wdPrintAllDocument, Item:=wdPrintDocumentContent, _
      Copies:=1, Pages:="", PageType:=wdPrintAllPages, Collate:=True, Background:=True
      Doc.Close SaveChanges:=False
    End If
  Next
End With
End Sub
 
Upvote 0
Thank you Macropod! It works perfectly.

One final question: so how does one get to be so good and knowledge with VBA code...i.e., how does one get to be a Macropod?
 
Upvote 0
One final question: so how does one get to be so good and knowledge with VBA code?
Much of what I've learnt has been from studying code others' have written, plus taking hints from what the macro recorder generates. And most of that has been for the purpose of helping people in forums such as this.
 
Upvote 0

Forum statistics

Threads
1,224,524
Messages
6,179,308
Members
452,904
Latest member
CodeMasterX

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top