# Word Macro to Print Multiple Documents



## FozzieBeara (May 12, 2011)

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. )

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
> ...


----------



## Macropod (May 12, 2011)

Hi FozzieBeara,

Try:

```
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
```


----------



## FozzieBeara (May 18, 2011)

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.


----------



## Macropod (May 18, 2011)

Hi FozzieBeara,

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


```
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
```


----------



## FozzieBeara (May 18, 2011)

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?


----------



## Macropod (May 18, 2011)

FozzieBeara said:


> 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.


----------

