在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
相关推荐
不想有bug的小菜鸟12 分钟前
vue3使用iframe全屏展示pdf效果
前端·pdf
IDRSolutions_CN18 小时前
(教程)PDF 字体技术入门
java·经验分享·pdf·软件工程·团队开发
恶猫1 天前
[特殊字符]清华大学:DeepSeek从入门到精通.pdf(清华领航,驾驭DeepSeek,开启AI新境界)
ai·pdf·deepseek
别拿曾经看以后~2 天前
【PDF预览】使用iframe实现pdf文件预览,加盖章
pdf
自然 醒2 天前
鸿蒙ArkTs如何实现pdf预览功能?
华为·pdf·harmonyos·harmonyosnext版本
Leo.yuan2 天前
48页PDF | GBT 36073-2018 数据管理能力成熟度评估模型 (附下载)
pdf
PythonFun2 天前
1分钟用DeepSeek编写一个PDF转Word软件
pdf·c#·word
William.csj2 天前
Matlab——图像保存导出成好看的.pdf格式文件
matlab·pdf
風落3 天前
PDF无限使用,永久免费!
pdf
littleBoy7774 天前
使用excel中的VBA合并多个excel文件
excel·vba