在VBA中调用Adobe Acrobat或Reader的命令行工具,实现PDF自动打印 (‾◡◝)

在VBA(Visual Basic for Applications)中自动打印PDF文件通常不直接支持,因为VBA本身是针对Microsoft Office应用程序(如Excel、Word和PowerPoint等)的编程语言,并不直接处理PDF文件。但是,你可以通过调用Adobe Acrobat或Reader的命令行工具间接实现自动打印PDF文件的功能。

一、操作步骤

首先需要为你的电脑安装Adobe Acrobat或Reader,你可以使用它们的命令行工具(如AcroRd32.exe)来打印PDF文件。其次需要Acrobat或Reader的安装路径(可能因版本和安装位置而异)。最后编写VBA代码调用命令行。

vbnet 复制代码
Sub PrintPDF()
    '自动打印单个PDF文件
    
    Const Path_Pdf As String = "C:\Users\Desktop\test.pdf"
    Const Adobe_exe As String = "C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe"
    Const Printer_Name As String = "Print Driver"
    Dim shellCommand As String
    
    shellCommand = Adobe_exe & " /p /h " & Path_Pdf
    Shell shellCommand, vbHide
    
End Sub


'选择打印机 /t
'shellCommand = Adobe_exe & " /p /h /t "& Printer_Name & Path_Pdf
vbnet 复制代码
Sub BatchPrintPDF()
    '批量打印PDF文件
    
    Const Path_Pdf As String = "C:\Users\Desktop\test"
    Const Adobe_exe As String = "C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe"
    Dim shellCommand As String

    Set fso = CreateObject("Scripting.FileSystemObject")
    Set Folder = fso.GetFolder(Path_Pdf)

    For Each file In Folder.Files
       shellCommand = Adobe_exe & " /p /h " & file
       Shell shellCommand, vbHide
    Next file
    
End Sub
相关推荐
开开心心就好10 小时前
免费PDF处理软件,支持多种操作
运维·服务器·前端·spring boot·智能手机·pdf·电脑
念九_ysl14 小时前
Java 使用 OpenHTMLToPDF + Batik 将含 SVG 遮罩的 HTML 转为 PDF 的完整实践
java·开发语言·pdf
一头生产的驴1 天前
java整合itext pdf实现自定义PDF文件格式导出
java·spring boot·pdf·itextpdf
开开心心就好2 天前
批量PDF转换工具,一键转换Word Excel
开发语言·前端·学习·pdf·电脑·word·excel
Prodigy_kyw2 天前
VBA初学3----实战(VBA实现Excel转csv)
excel·vba·csv
老家的回忆3 天前
jsPDF和html2canvas生成pdf,组件用的elementplus,亲测30多页,20s实现
前端·vue.js·pdf·html2canvas·jspdf
Vertira3 天前
pdf 合并 python实现(已解决)
前端·python·pdf
十一0829933 天前
【PDF-XSS攻击】springboot项目-上传文件-解决PDF文件XSS攻击
spring boot·pdf·xss
qq_393828223 天前
PDF的图片文字识别工具
windows·pdf·电脑·软件需求·图片处理
wsxqaz3 天前
浏览器原生控件上传PDF导致hash值不同
算法·pdf·哈希算法