|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
用的代码是这个,不一样
'Rem ******* 北极狐工作室出品 ******
'Rem ******* QQ:14885553 *****
'Rem **********************************
Option Explicit '//强制声明变量
Sub TEST()
Dim PathPDF As String
PathPDF = ThisWorkbook.Path & "\630.PDF"
Call PrintPDFFile(PathPDF:=PathPDF, FirstPage:=1, LastPage:=5)
End Sub
Sub PrintPDFFile(ByVal PathPDF As String, Optional ByVal FirstPage As Long = 1, Optional ByVal LastPage As Long = 0)
Rem PathPDF 需要打印的PDF文件的全路径
Rem FrstPage 要打印的第一页 默认=1
Rem LastPage 要打印的最后一页 默认=0 全部
Rem 必要时需引用:Adobe Acrobat 10.0 Type Library (版本可能不一样)
Dim AcroExchApp As Acrobat.CAcroApp
Dim AcroExchAVDoc As Acrobat.CAcroAVDoc
Dim AcroExchPDDoc As Acrobat.CAcroPDDoc
Dim NumPage As Long
Set AcroExchApp = CreateObject("AcroExch.App")
Set AcroExchAVDoc = CreateObject("AcroExch.AVDoc")
Rem 打开PDF Open the [PathPDF] pdf file
AcroExchAVDoc.Open PathPDF, "1"
Rem 转为另一个对象 主要是获取页码 Get the PDDoc associated with the open AVDoc
Set AcroExchPDDoc = AcroExchAVDoc.GetPDDoc
Rem 获取页码, 第一页=0 Get the number of pages for this pdf
NumPage = AcroExchPDDoc.GetNumPages - 1
Rem 内部的页码是从0开始的 就是第一页的序号=0
If FirstPage > 0 Then FirstPage = FirstPage - 1
If LastPage > 0 Then
LastPage = LastPage - 1
Else
LastPage = NumPage
End If
Rem 防止指定的最后一页 超过实际页数
If LastPage > NumPage Then LastPage = NumPage
Rem 开始打印
Rem Call AcroExchAVDoc.PrintPages(FirstPage, LastPage, 2, 1, 1) '//打印指定范围的页面,显示打印对话框。PrintPages始终使用 WIN中的默认打印机设置?INI?
Call AcroExchAVDoc.PrintPagesSilent(FirstPage, LastPage, 2, 1, 1) '//打印指定范围的页面而不显示任何对话框
Rem 关闭Adobe对象
AcroExchApp.Exit
AcroExchAVDoc.Close (False)
AcroExchPDDoc.Close
End Sub |
|