在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
相关推荐
SamChan909 小时前
用PostgreSQL+pgvector构建PDF翻译记忆库:向量相似度检索+增量更新实战
数据库·python·ai·postgresql·pdf·wpf
2601_963906781 天前
中文线装古籍电子书排版一键生成工具,PDF导出
pdf·软件需求
百事牛科技1 天前
只可读不可改!PDF禁止修改实操方法
windows·pdf
fruge1 天前
不用反复折腾 Word 排版:本地部署 Magic Resume,在线编辑并导出 PDF
pdf
gsls2008081 天前
Penpot 导出 PDF 报错 —— 问题排查与解决记录
pdf·原型·penpot
SamChan901 天前
PDF 翻译服务的全链路可观测性设计:OpenTelemetry + Jaeger + Loki 实战方案
后端·python·pdf·机器翻译
Source.Liu2 天前
【A11】基于 PDF 渲染引擎的统一文档界面架构设计
rust·pdf
zhonyu鱼3 天前
Saber:专为触控笔设计的开源手写笔记与 PDF 批注工具
笔记·pdf·开源
winfredzhang3 天前
用 Python + wxPython 造一个照片工具箱:PDF / 加密ZIP / MP4 / 归档,以及我在这过程中踩到的 4 个坑
python·pdf·zip·mp4·移动
2501_930707784 天前
使用C#代码在 PDF 文档中创建列表
pdf