2
votes

Ok so i print about 200+ pdf's every day. I know i can ctrl A and drag them to the printer but every time i do that it prints around 3 out 5 pdf's. Is there a way i can write a macros telling it to print each pdf and wait 3 or 5 seconds to print the next one?

so far i have this:

Option Explicit 

Declare Function apiShellExecute Lib "shell32.dll" Alias "ShellExecuteA" ( _ 
ByVal hwnd As Long, _ 
ByVal lpOperation As String, _ 
ByVal lpFile As String, _ 
ByVal lpParameters As String, _ 
ByVal lpDirectory As String, _ 
ByVal nShowCmd As Long) _ 
As Long 

Public Sub PrintFile(ByVal strPathAndFilename As String) 

    Call apiShellExecute(Application.hwnd, "print", strPathAndFilename, vbNullString, vbNullString, 0) 

End Sub 

Sub Test() 

    PrintFile ("C:\Users\gutierrezs\downloads") 

End Sub 

its not working for me becuase i think the above was only meant to search for a file name and print one.

2

2 Answers

1
votes

What you probably need to do is create a list of each file in the folder that contains the .pdfs that you want to print and then print each of them.

How to make a list of all PDF's

You can use the Wait method to wait for 3 seconds if you have to

1
votes

Here is a vbs script I modified to:

executeGlobal CreateObject("Scripting.FileSystemObject").openTextFile(".\printPdfSrcFiles.vbs").readAll()

'Wscript.Quit()

Dim pdfKey, printCmd, printJob, strMsg, pdfNo, objShell

' Read PDF print command from the registry
Set objShell = CreateObject( "WScript.Shell" )
pdfKey = objShell.RegRead( "HKCR\.pdf\" )
printCmd = objShell.RegRead( "HKCR\" & pdfKey & "\shell\print\command\" )
If InStr( printCmd, "{" ) Then MsgBox ("Adobe Reader is not your edfault pdf reader")

Set objArgs = WScript.Arguments

For pdfNo = 1 to pdfFiles.Count
    printJob = Replace( printCmd, "%1", pdfFiles(pdfNo))
    WScript.Sleep 1000
    objShell.Run(printJob)
Next
' Done

WScript.Quit(0)

printPdfSrcFiles.vbs contains:

dim pdfFiles
dim i
set pdfFiles = CreateObject("Scripting.Dictionary")
i = 1

call pdfFiles.Add(i, "yourFirstPDFFilePath.pdf") : i = i + 1
call pdfFiles.Add(i, "yourSecondPDFFilePath.pdf") : i = i + 1
etc...

crucial for you is WScript.Sleep 1000 which waits one second before printing another file, surely you can retrieve your pdf list from another source e.g. Excel sheet.