首页 文章

VBA打印已保存的多个PDF但每3秒打印一次?

提问于
浏览
1

好的,所以我每天打印约200份pdf . 我知道我可以控制A并将它们拖到打印机,但每次我这样做它会打印出3个5个pdf . 有没有办法我可以写一个宏告诉它打印每个pdf并等待3或5秒打印下一个?

到目前为止我有这个:

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

它不适合我,因为我认为以上只是为了搜索文件名并打印一个 .

2 回答

  • 0

    您可能需要做的是在包含要打印的.pdfs的文件夹中创建每个文件的列表,然后打印每个文件 .

    How to make a list of all PDF's

    如果必须,可以使用Wait方法等待3秒

  • 0

    Here是我修改为的vbs脚本:

    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包含:

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

    对你来说至关重要的是 WScript.Sleep 1000 ,在打印另一个文件之前等待一秒钟,你肯定可以从其他来源检索你的pdf列表,例如Excel表格 .

相关问题