在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
相关推荐
阿幸软件杂货间4 小时前
Office转PDF转换器v1.0.py
开发语言·pdf·c#
reembarkation8 小时前
使用pdfjs-dist 预览pdf,并添加文本层的实现
前端·javascript·pdf
reembarkation8 小时前
vue-pdf 实现blob数据的预览
javascript·vue.js·pdf
Light6014 小时前
领码方案|Linux 下 PLT → PDF 转换服务超级完整版:异步、权限、进度(一气呵成)
linux·spring boot·pdf·gpcl6/ghostpcl·s3/oss·权限与审计·异步与进度
伟贤AI之路16 小时前
【分享】中小学教材课本 PDF 资源获取指南
人工智能·pdf
东风西巷1 天前
PDFgear:免费全能的PDF处理工具
前端·pdf·软件需求
Sunny_yiyi2 天前
Java根据模版导出PDF文件
java·开发语言·pdf
小*-^-*九2 天前
php 使用html 生成pdf word wkhtmltopdf 系列2
pdf·html·php
千册2 天前
pyside6 的pdf显示测试 -- 01
开发语言·python·pdf
qq_172805592 天前
Go 语言 PDF 生成库综合比较与实践指南
开发语言·golang·pdf