使用 VBA 打开 Acrobat 文件
Opening Acrobat Files using VBA
我正在阅读论坛帖子:
https://forums.adobe.com/thread/604177
并开始试验它。但我认为该功能根本没有加载。我不确定背后的原因是什么——我认为它必须很简单并且可能与图书馆有关。有人可以帮助指出为什么以下代码根本无法编译(代码在立即执行时似乎没有 运行,因为 none 触发了断点)。
我加载的库包括
- Acrobat 蒸馏器
- Adobe Acrobat 10.0 类型库
- Acrobat Scan 1.0 类型库
执行这段代码的电脑安装了Acrobat Professional。
Public Function GetPDF() '(FilePath As String) As Object
Dim origPdf As Acrobat.AcroPDDoc
Dim path1 As String
MsgBox ("Start")
path1 = Application.ActiveWorkbook.Path
path1 = path1 & "700100.pdf"
Set origPdf = CreateObject("AcroExch.PDDoc")
If origPdf.Open(path1) Then
MsgBox ("weee")
End If
origPdf.Close
Set origPdf = Nothing
End Function
用这个创建一个模块:
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
Sub GetPDF()
Dim path1 As String
MsgBox "Start"
path1 = Application.ActiveWorkbook.Path
path1 = path1 & "700100.pdf"
ShellExecute 0, "Open", path1, "", "", _
vbNormalNoFocus
End Sub
在 VBA 中打开文档需要您拥有 Acrobat App 对象。一旦您在函数中有一个 app 对象,该代码就会起作用。
Public Function GetPDF (FilePath As String) As Object
Dim ArcoApp As New Acrobat.AcroApp
Dim OriPdf As New Acrobat.AcroPDDoc
Set ArcoApp = CreateObject("AcroExch.App")
Set OriPdf = CreateObject("AcroExch.PDDoc")
If OriPdf.Open(FilePath) Then
MsgBox ("weee")
End If
GetPDF = OriPdf
OriPdf.Close
AcroApp.Close
Set OriPdf = Nothing
Set AcroApp = Nothing
End Function
我正在阅读论坛帖子: https://forums.adobe.com/thread/604177 并开始试验它。但我认为该功能根本没有加载。我不确定背后的原因是什么——我认为它必须很简单并且可能与图书馆有关。有人可以帮助指出为什么以下代码根本无法编译(代码在立即执行时似乎没有 运行,因为 none 触发了断点)。
我加载的库包括
- Acrobat 蒸馏器
- Adobe Acrobat 10.0 类型库
- Acrobat Scan 1.0 类型库
执行这段代码的电脑安装了Acrobat Professional。
Public Function GetPDF() '(FilePath As String) As Object
Dim origPdf As Acrobat.AcroPDDoc
Dim path1 As String
MsgBox ("Start")
path1 = Application.ActiveWorkbook.Path
path1 = path1 & "700100.pdf"
Set origPdf = CreateObject("AcroExch.PDDoc")
If origPdf.Open(path1) Then
MsgBox ("weee")
End If
origPdf.Close
Set origPdf = Nothing
End Function
用这个创建一个模块:
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
Sub GetPDF()
Dim path1 As String
MsgBox "Start"
path1 = Application.ActiveWorkbook.Path
path1 = path1 & "700100.pdf"
ShellExecute 0, "Open", path1, "", "", _
vbNormalNoFocus
End Sub
在 VBA 中打开文档需要您拥有 Acrobat App 对象。一旦您在函数中有一个 app 对象,该代码就会起作用。
Public Function GetPDF (FilePath As String) As Object
Dim ArcoApp As New Acrobat.AcroApp
Dim OriPdf As New Acrobat.AcroPDDoc
Set ArcoApp = CreateObject("AcroExch.App")
Set OriPdf = CreateObject("AcroExch.PDDoc")
If OriPdf.Open(FilePath) Then
MsgBox ("weee")
End If
GetPDF = OriPdf
OriPdf.Close
AcroApp.Close
Set OriPdf = Nothing
Set AcroApp = Nothing
End Function