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

VBA打印多个PDF';已保存但每3秒打印一个的?,vba,excel,pdf,printing,Vba,Excel,Pdf,Printing,好的,我每天打印200多张pdf。我知道我可以按住ctrl键A并将它们拖到打印机上,但每次我这样做时,它都会打印出大约3/5的pdf。有没有一种方法可以让我编写一个宏,告诉它打印每个pdf文件,然后等待3或5秒打印下一个 到目前为止,我有: Option Explicit Declare Function apiShellExecute Lib "shell32.dll" Alias "ShellExecuteA" ( _ ByVal hwnd As Long, _ ByVal lpOp

好的,我每天打印200多张pdf。我知道我可以按住ctrl键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 选项显式 声明函数apishellexecutelib“shell32.dll”别名“ShellExecuteA”(\u 再见,只要 ByVal lpOperation作为字符串,\u ByVal lpFile作为字符串,\u ByVal lpParameters作为字符串,\u ByVal lpDirectory作为字符串,\u ByVal nShowCmd(如长)\u 只要 公共子打印文件(ByVal strPathAndFilename作为字符串) 调用apiShellExecute(Application.hwnd,“print”,strPathAndFilename,vbNullString,vbNullString,0) 端接头 子测试() 打印文件(“C:\Users\gutierrezs\downloads”) 端接头
这对我不起作用,因为我认为上面的内容只是为了搜索一个文件名并打印一个文件名

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

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

是一个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
,它会在打印另一个文件之前等待一秒钟,您当然可以从另一个源(例如Excel工作表)检索pdf列表。

我如何将其与上面的代码结合起来修改它?请注意,我正在保存的文件夹中的所有内容都是PDF,该文件夹中的所有PDF都需要打印。难道没有一种方法可以编写一个代码来打印目录中的所有内容吗?