gpt4 book ai didi

vba - 使用 VBA 打开 .pdf

转载 作者:行者123 更新时间:2023-12-04 21:04:19 27 4
gpt4 key购买 nike

我有下面的代码,它似乎没有打开 pdf 请帮助。我对 VBA 非常流利,但对 adobe 中的 vba 面向对象代码不熟悉。

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

关于vba - 使用 VBA 打开 .pdf,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28091970/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com