用VBA打开.pdf

我有下面的代码,似乎不打开PDF请帮助。 我非常stream利地使用VBA,但没有使用面向对象的代码与Adobe。

Option Explicit Option Compare Text Sub SeperatePDFFile() Dim selectpdf As String Dim caption As String Dim filter As String Dim gApp As Acrobat.AcroApp Dim gPDDoc As Acrobat.AcroPDDoc Set gApp = CreateObject("AcroExch.App") Set gPDDoc = CreateObject("AcroExch.PDDoc") caption = "Please Select an input file must extension .pdf" selectpdf = Application.GetOpenFilename(filter, , caption) gPDDoc.Open (selectpdf) End Sub 

如果你只需要打开PDF,是否有任何理由自动化Acrobat,而不是感谢只使用ShellExecute(它打开几乎所有在Windows注册的文件)?

 Option Explicit Private 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 Test() If LaunchFile("C:\temp\somefile.pdf") > 32 Then ' it worked, the file's open Else ' failed for some reason End If End Sub Function LaunchFile(sFileName As String) As Long ' Requires the full path to the file to be launched LaunchFile = ShellExecute(0&, vbNullString, sFileName, vbNullString, vbNullString, vbNormalFocus) End Function