在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
相关推荐
阿幸软件杂货间5 小时前
免费万能电子书格式转换器!Neat Converter支持 ePub、Azw3、Mobi、Doc、PDF、TXT 文件的相互转换。
pdf·格式转换
星马梦缘14 小时前
CSDN转PDF【无水印且免费!!!】
pdf·免费·pandoc·转pdf·无水印·csdn转pdf·wkhtmlpdf
画月的亮14 小时前
前端处理导出PDF。Vue导出pdf
前端·vue.js·pdf
伊织code1 天前
pdfminer.six
python·pdf·图片·提取·文本·pdfminer·pdfminer.six
HAPPY酷2 天前
给纯小白的Python操作 PDF 笔记
开发语言·python·pdf
代码AI弗森3 天前
PDF OCR + 大模型:让文档理解不止停留在识字
pdf·ocr
小周同学:3 天前
在 Vue2 中使用 pdf.js + pdf-lib 实现 PDF 预览、手写签名、文字批注与高保真导出
开发语言·前端·javascript·vue.js·pdf
Kyln.Wu4 天前
【python实用小脚本-187】Python一键批量改PDF文字:拖进来秒出新文件——再也不用Acrobat来回导
python·pdf·c#
迪尔~5 天前
Apache POI中通过WorkBook写入图片后出现导出PDF文件时在不同页重复写入该图片问题,如何在通过sheet获取绘图对象清除该图片
java·pdf·excel
忆~遂愿5 天前
Python实战教程:PDF文档自动化编辑与图表绘制全攻略
python·pdf·自动化