单击按钮时,我的代码使用
Application.FollowHyperlink
打开远程服务器上的 PDF。包含该文件的文件夹已通过向每个人授予完全控制权来共享。该文件使用 Adobe Acrobat 打开,这很奇怪,因为在本地服务器上打开 PDF 的默认程序设置为 Chrome。文件大约 4 秒后关闭,不知道为什么。我可以导航到本地服务器上该文件所在的文件夹,然后使用 Chrome 打开它。我还可以通过 RDP 进入远程服务器,并默认使用 Edge 打开那里的文件,没有任何问题。远程服务器未安装 Adobe Acrobat。
Private Sub btnOpenCert_Click()
Dim WO As String
Dim CoCFolder As String
Dim CustPO As String
Dim FilePath As String
WO = FieldOnForm
'...run a stored procedure using an ADODB connection, then interpret results...
CoCFolder = GetCoCFolder()
CustPO = GetPropertyFromWO(WO, 1)
FilePath = CoCFolder & CustPO & "_" & WO & ".pdf"
Application.FollowHyperlink FilePath
ExitLabel:
Exit Sub
ErrLabel:
ErrHandler Err.Number, Err.Description
Resume ExitLabel
End Sub
改编自我上面发布的链接的解决方法:
Option Explicit
Private Const SW_SHOWMAXIMIZED = 3
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 tester()
Dim pdf As String
pdf = "\\serverHere\path1\path2\someDocument.pdf"
Debug.Print gbOpenFile(pdf)
End Sub
Public Function gbOpenFile(rsPath As String) As Boolean
If ShellExecute(0, "open", rsPath & vbNullChar, vbNullString, _
vbNullString, SW_SHOWMAXIMIZED) > 32 Then
gbOpenFile = True
End If
End Function
请注意,这适用于 32 位:如果您有 64 位访问权限,则需要进行任何适当的更改。