【问题标题】:VBA to print multiple PDF's that are already saved but to print one every 3 seconds?VBA打印多个已经保存但每3秒打印一个的PDF?
【发布时间】:2017-12-27 12:34:10
【问题描述】:

好的,所以我每天打印大约 200 多个 pdf。我知道我可以 ctrl A 并将它们拖到打印机上,但每次我这样做时,它都会打印大约 5 个 pdf 文件中的 3 个。有没有办法我可以编写一个宏来告诉它打印每个 pdf 并等待 3 或 5 秒以打印下一个?

到目前为止我有这个:

选项显式 声明函数 apiShellExecute Lib "shell32.dll" 别名 "ShellExecuteA" (_ ByVal hwnd 只要,_ ByVal lpOperation 作为字符串,_ ByVal lpFile 作为字符串,_ ByVal lpParameters 作为字符串,_ ByVal lpDirectory 作为字符串,_ ByVal nShowCmd 只要)_ 只要 公共子打印文件(ByVal strPathAndFilename 作为字符串) 调用 apiShellExecute(Application.hwnd, "print", strPathAndFilename, vbNullString, vbNullString, 0) 结束子 子测试() PrintFile ("C:\Users\gutierrezs\downloads") 结束子

它对我不起作用,因为我认为上面的内容只是为了搜索文件名并打印一个。

【问题讨论】:

    标签: vba excel pdf printing


    【解决方案1】:

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

    How to make a list of all PDF's

    必要时可以使用Wait方法等待3秒

    【讨论】:

    • 我如何将它与我上面的代码结合起来改变它?请注意,我保存的该文件夹中的所有内容都是 PDF,并且该文件夹中的每个 pdf 都需要打印。有没有办法只编写代码来打印该目录中的所有内容?
    【解决方案2】:

    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 工作表。

    【讨论】:

      猜你喜欢
      • 2019-06-09
      • 2020-02-11
      • 2012-08-27
      • 1970-01-01
      • 2010-10-20
      • 2013-05-25
      • 2017-08-23
      • 2019-05-03
      相关资源
      最近更新 更多