# Can I print a word document without opening word?



## kentgorsuch (Sep 30, 2006)

Please help!

I am trying to print from the windows explorer window by using the “right click” button on the keyboard (along with “P”) to send documents to the printer one after another. Word wants to open and close every document prior to printing which takes forever (5 to 8 seconds), a long time when you have several hundred documents to print)! It also grabs focus from the explorer window so I can’t jump to another document until it closes and returns focus back to the explorer window. I used to do this from Word Perfect with no problem! Can a script or some code be created to make Word behave???

Thanks in advance for any help!


----------



## Glaswegian (Sep 16, 2005)

Hi and welcome to TSF.

The only way you can do this, AFAIK, is to create a macro, in Word, and run it from there. I've done this once, but a good while ago, so hopefully this code will still work. Ideally, have all the docs to be printed in one separate folder. This makes use of the *PrintOut* method - and the files don't have to be open.

Open Word and press Alt+F11 - the Visual Basic Editor will open. Click on 'Normal.dot' in the left pane, then go to Insert > Module. A new Module will open up in the right pane. Copy and paste this code to the right pane.

```
Sub PrintAllDocsAtOnce()
Dim objWord As Object
Dim objDoc As Document
Dim objFile As Object
Dim strComputer As String
Dim objWMIService As Object
Dim FList


Set objWord = CreateObject("Word.Application")
objWord.Visible = True
Set objDoc = objWord.Documents.Add()

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set FList = objWMIService.ExecQuery _
    ("ASSOCIATORS OF {Win32_Directory.Name='[b][color=#FF0000]c:\Test[/color][/b]'} Where " _
        & "ResultClass = CIM_DataFile")

For Each objFile In FList
    If objFile.Extension = "doc" Then
        objWord.PrintOut , , , , , , , , , , , , objFile.Name
    End If
Next

objWord.Quit
End Sub
```
Note that I've *bolded* and coloured the directory name - this will need changed to wherever your files are located. Make sure you keep the single quotes around the name. I also suggest testing with a small number of files in a test folder beforehand - just in case you encounter any problems. I've tested this without printing - I just used a message box - and it returned all the Word docs in my test folder so you should be OK.

Now run your macro and collect your paper!


----------



## nickster_uk (Feb 7, 2005)

Cool this will come in handy, thanks Iain!


----------

