# Printing Multiple files from a folder



## eathen (Jul 24, 2006)

I would like to know how to print multiple files in a folder. For example, a folder contains 50 Ms Word documents that needs to be printed. I do not want to open each document to print. The driver I have for HP laserjet 4300tn is updated. Is there a batch file that needs to be created? Is there a solution to this issue? Or is there a workaround?

Tested the following attempts, nothing gets printed
I tried selecting all the document, right click>print.
Selected all the document, then dragged them onto the printer icon. 
Copied the printer icon into the "send to" option, then selected all the document and selected send to> printer_name.


----------



## StumpedTechy (Jul 7, 2004)

I am thinking something is wrong.. you should be able to print doing it the ways you did -

http://www.samspublishing.com/articles/article.asp?p=131310&seqNum=3&rl=1

Have you tried totally uninstalling, shutting down, reinstalling the print driver?


----------



## eathen (Jul 24, 2006)

Even after deleting the printer and reinstalling it from scrath does not help. The printer is networked in our office, does this have an effect?


----------



## kenneth2k1 (Oct 9, 2003)

One guess I have is to check the amount of installed RAM. If the size of the print job exceeds the amount of RAM the printer has, it may drop the jobs all together. Also, try only selecting 5 or so files to print and see if they go through.


----------



## Squashman (Apr 4, 2003)

Funny you should mention this, we are experiencing the same problem on one of the PC's here at work. The user is trying to print about 40 single page text files and it will only print about three of them everytime we try selecting them all and right clicking to print. I have always done that method in the past but it doesn't seem to be working on her pc which is Windows 2000 SP4


----------



## kenneth2k1 (Oct 9, 2003)

I had a similar problem once, and the job wasn't spooling properly. It would get to a certain size and stop building the print job. Then the job never went through. What solved it was installing a network print monitor (it came with the printer's software) and that made the jobs go through for some reason. That was on 2k SP4 printing to a Canon imageclass.


----------



## eathen (Jul 24, 2006)

I am pretty sure the printer has enough ram to carry out the request. I believe the printer has 256 MB ram.
I have tried printing 15, 10, 5, 2 files at a time, I don&#8217;t even see the printer icon that come up in the system tray and the printer status is Ready.
It only prints single pages at a time.
Do guys think there is free third party software that will perform this function?
At our office we are running winxp pro sp2


----------



## Rollin_Again (Sep 4, 2003)

You can use a VBA script or macro to do this. Does the directory containing the word files contain any other file types?

Put the following code into a notepad file and rename the file extension to *.VBS*
Make sure to change the file path to the path of your actual directory. Then save the VBS file and double click to execute.


```
set shApp = createobject("shell.application") 
set shFolder = shApp.namespace("C:\TEST") 
set ****ems = shFolder.Items() 
for each ****em in ****ems 
  ****em.invokeverb "&Print" 
next
```
Rollin


----------



## eathen (Jul 24, 2006)

Thank you all for your help.
Rollin_Again nailed my question. Thanks a lot.
The folder only contained Ms Word documents. I have not tested with other file formats. How would you create a Macro for this issue? 
Thank you once again.


----------



## Rollin_Again (Sep 4, 2003)

The instructions for creating the stand-alone VB Script are in my post above. If you would rather have the code executed directly out of word let me know and I'll write the code for you.

Rollin


----------



## eathen (Jul 24, 2006)

You have resolved my issue. 
But for reference in the future, I would not mind having the code execute directly out of Word.


----------



## Rollin_Again (Sep 4, 2003)

Sorry it took so long to get back. I've attached a word document with the macro already attached. Just open the word document and run the macro called "PrintAll" This will pop up an explorer style window that will allow you to click the directory that want to print the contents of. The code currently assumes that the directory only contains word documents. It can be easily modified to include logic to ignore any files that are not word documents.

Copy and paste the following code into a blank module in Word and then run the macro called "PrintAll"


```
'API Declares
Private Declare Function SendMessage Lib "USER32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function SHBrowseForFolder Lib "shell32.dll" Alias "SHBrowseForFolderA" (lpbi As BrowseInfo) As Long
Private Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As Long
Private Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal hMem As Long)

'API Constants
Private Const MAX_PATH = 260
Private Const BIF_RETURNONLYFSDIRS = 1
Private Const BIF_STATUSTEXT = 4

Private Const WM_USER = &H400
Private Const BFFM_INITIALIZED = 1
Private Const BFFM_SELCHANGED = 2
Private Const BFFM_SETSTATUSTEXTA = (WM_USER + 100)

Private Const BFFM_SETSELECTIONA = (WM_USER + 102)


'BrowseInfo Type
Private Type BrowseInfo
    hwndOwner As Long
    pIDLRoot As Long
    pszDisplayName As String
    lpszTitle As String
    ulFlags As Long
    lpfn As Long
    lParam As Long
    iImage As Long
End Type

'Private Variables
Private m_sDefaultFolder As String
Public Sub BrowseFolder()

frmBrowse.Show
frmBrowse.txtDirectory.Text = ""


End Sub

Public Function BrowseForFolder(DefaultFolder As String, Optional Parent As Long = 0, Optional Caption As String = "") As String
    Dim bi As BrowseInfo
    Dim sResult As String, nResult As Long

    bi.hwndOwner = Parent
    bi.pIDLRoot = 0
    bi.pszDisplayName = String$(MAX_PATH, Chr$(0))
    If Len(Caption) > 0 Then
        bi.lpszTitle = Caption
    End If
    bi.ulFlags = BIF_RETURNONLYFSDIRS
    bi.lpfn = GetAddress(AddressOf BrowseCallbackProc)
    bi.lParam = 0
    bi.iImage = 0

    m_sDefaultFolder = DefaultFolder

    nResult = SHBrowseForFolder(bi)

    If nResult <> 0 Then
        sResult = String(MAX_PATH, 0)
        If SHGetPathFromIDList(nResult, sResult) Then
            BrowseForFolder = Left$(sResult, InStr(sResult, Chr$(0)) - 1)
        End If

        CoTaskMemFree nResult
    End If
End Function


Private Function BrowseCallbackProc(ByVal hwnd As Long, ByVal uMsg As Long, ByVal lParam As Long, ByVal lpData As Long) As Long
    Select Case uMsg
        Case BFFM_INITIALIZED

            If Len(m_sDefaultFolder) > 0 Then

                SendMessage hwnd, BFFM_SETSELECTIONA, True, ByVal m_sDefaultFolder
            End If
    End Select
End Function


Private Function GetAddress(nAddress As Long) As Long
    GetAddress = nAddress
End Function

Public Sub PrintAll()

Dim txtDirectory As String

txtDirectory = BrowseForFolder(txtDirectory, , "&Select a directory:")


With Application.FileSearch
.NewSearch
.LookIn = txtDirectory
.SearchSubFolders = False
.FileType = msoFileTypeWordDocuments
If .Execute() > 0 Then
For i = 1 To .FoundFiles.Count
Application.PrintOut , , , , , , , , , , , , CStr(.FoundFiles(i))
Next i
End If
End With

End Sub
```
Regards,
Rollin


----------



## eathen (Jul 24, 2006)

Thank you again Rollin_Again for you input for my thread.


----------



## Rollin_Again (Sep 4, 2003)

Glad to help!! Did you download the zip file I attached to my last post? It is a sample word document that does exactly what you want and you can just click on the folder you want to print from.

Rollin


----------



## peglar (Apr 18, 2007)

I have tried your word doc macro and it almost does exactly what i require, however i am trying to do this with html files and although it prints them word is formatting them to have odd spacing etc. 

would it be possible to do this as a standalone .exe?

my knowledge of VB is appaling at best.


----------



## Rollin_Again (Sep 4, 2003)

Are you trying to print the actual web page itself or the html source code?

If you want the code to run as a stand-alone project it likely can be done through a VBS Script.

Regards,
Rollin


----------



## peglar (Apr 18, 2007)

i am trying to print the web pages.

you see we have a system here that generates reports and they are .htm but we have around 200 at a time that get generated. They all get sent to one folder so it would be great if we could have a program that we could run that prints off the web pages without having to go through the choose a printer dialogue box and without word formatting the web page badly.


----------



## peglar (Apr 18, 2007)

I have managed to solve it using ie instead of word. below is the code extract for the project, just incase it is of some use to someone else.



> Imports Microsoft.Win32
> Public Class Form1
> Dim pageKey As RegistryKey = Registry.CurrentUser.OpenSubKey("software\microsoft\internet explorer\pagesetup", True)
> 
> ...


the registry stuff was so that it would remove headers and footers from the print and then replace them once the printing had been done.


----------



## peglar (Apr 18, 2007)

i have been updating this program to add a browse for folder function and it now prints word documents too. next i will be working on adding pdf functionality as well.

pm me if you need help with word doc printing or adding a browse function to your program.


----------



## Rollin_Again (Sep 4, 2003)

I've already posted code with a browse to folder function.

Regards,
Rollin


----------



## peglar (Apr 18, 2007)

so you have!

i wish i had noticed that before spending ages trying to do it myself! oops


----------



## Rollin_Again (Sep 4, 2003)

Peglar,

Did you get this sorted yet?

Regards,
Rollin


----------



## peglar (Apr 18, 2007)

yeah, you can sign it off as solved!


----------

