简体   繁体   English

使用打印 scope 字符串打印特定页面表格 pdf 文件

[英]printing specific pages form pdf file using print scope string

I need to print selected pages of *.pdf file using excel VBA.我需要使用 excel VBA 打印 *.pdf 文件的选定页面。 I need to do this not by providing scope "from - to" but giving scoope of pages like "1-3,4,8, 17-25"我需要做到这一点不是通过提供 scope “从 - 到”,而是提供像“1-3,4,8,17-25”这样的页面

I can only print whole file using below code:我只能使用以下代码打印整个文件:

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 ```

Judging from this post , it is not possible using ShellExecute alone.这篇文章来看,单独使用ShellExecute是不可能的。 What you would need is to write a script which will open the file in whatever PDF reader you have installed, find a "Print" button there and provide all the options.您需要编写一个脚本,该脚本将在您安装的任何 PDF 阅读器中打开文件,在此处找到“打印”按钮并提供所有选项。 This will take a huge amount of work and will depend on the version of Windows and the PDF reader, so basically it will work only for you, and not for other users.这需要大量的工作,并且取决于 Windows 和 PDF 阅读器的版本,所以基本上它只适用于您,而不适用于其他用户。 If you want to go this path though, take a look at FindWindow and SendMessage WinAPI functions.如果你想 go 这个路径,看看FindWindowSendMessage WinAPI 函数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM