excel - 使用打印范围字符串打印特定页面表单pdf文件
问题描述
我需要使用 excel VBA 打印 *.pdf 文件的选定页面。我需要通过提供范围“从 - 到”而不是通过提供诸如“1-3,4,8,17-25”之类的页面来做到这一点
我只能使用以下代码打印整个文件:
Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" ( _
ByVal hwnd As Long, _
ByVal lpOperation As String, _
ByVal lpFile As String, _
ByVal lpParameters As String, _
ByVal lpDirectory As String, _
ByVal nShowCmd As Long) As Long
Public Function PrintThisDoc(formname As Long, FileName As String)
On Error Resume Next
Dim X As Long
X = ShellExecute(formname, "Print", FileName, 0&, 0&, 3)
End Function
Sub testPrint()
Dim printThis
Dim strDir As String
Dim strFile As String
strDir = "C:\Users\any\Desktop"
strFile = "somefile.pdf"
printThis = PrintThisDoc(0, strDir & "\" & strFile)
End Sub ```
解决方案
从这篇文章来看,单独使用是不可能的ShellExecute
。您需要编写一个脚本,该脚本将在您安装的任何 PDF 阅读器中打开文件,在此处找到“打印”按钮并提供所有选项。这需要大量的工作,并且取决于 Windows 和 PDF 阅读器的版本,所以基本上它只适用于您,而不适用于其他用户。但是,如果您想走这条路,请查看FindWindow
WinAPISendMessage
函数。
推荐阅读
- c# - 使用 StartsWith 的 Lambda 过滤在 c# 中不起作用
- docker - Docker将文件夹添加到图像中
- git - Git 工作流合并到 Master 并创建版本忽略一些合并
- javascript - 可定制的框架和库有什么区别?
- javascript - props 数组是否需要深拷贝?
- php - 带有 JSON 到 PHP 的 jQuery AJAX 请求
- java - 如何提高 Kafk 的消费者分区重新分配时间
- php - laravel 无法显示搜索结果
- sql - 基于时间戳派生一个新列
- ios - 如何在 Unity for iOS 中创建一个不响应多点触控的按钮?