在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
相关推荐
行者将至X2 小时前
解决Zotero翻译插件Zotero PDF Translate无法正常翻译
pdf
先树立一个小目标2 小时前
react-pdf(pdfjs-dist)如何兼容老浏览器(chrome 49)
chrome·react.js·pdf
空中湖6 小时前
免费在线PDF转图片工具
pdf·html
沉到海底去吧Go9 小时前
【PDF识别改名】PDF指定区域OCR识别重命名工具使用教程和注意事项
python·pdf·ocr
空中湖9 小时前
免费批量PDF转Word工具
pdf·word
mangge089 小时前
python读取SQLite表个并生成pdf文件
pdf
开开心心就好9 小时前
免费PDF转图片软件
javascript·智能手机·pdf·flask·word·excel·scikit-learn
Eiceblue17 小时前
Python读取PDF:文本、图片与文档属性
数据库·python·pdf
AAA_自动化工程师20 小时前
TIA博途中的程序导出为PDF格式的具体方法示例
pdf·tia博途·程序导出·pdf格式·具体方法
行云流水剑20 小时前
【学习记录】如何使用 Python 提取 PDF 文件中的内容
python·学习·pdf