Open a PDF using VBA in Excel

后端 未结 5 1881
南笙
南笙 2020-12-10 15:18

I\'m trying to open all appropriate PDFs found in the same directory as my Excel workbook using VBA. I\'ve added the Adobe Acrobat xx.x Type Library reference to the projec

5条回答
  •  执笔经年
    2020-12-10 15:57

    WOW... In appreciation, I add a bit of code that I use to find the path to ADOBE

    Private Declare Function FindExecutable Lib "shell32.dll" Alias "FindExecutableA" _
        (ByVal lpFile As String, _
         ByVal lpDirectory As String, _
         ByVal lpResult As String) As Long
    

    and call this to find the applicable program name

    Public Function GetFileAssociation(ByVal sFilepath As String) As String
    Dim i               As Long
    Dim E               As String
        GetFileAssociation = "File not found!"
        If Dir(sFilepath) = vbNullString Or sFilepath = vbNullString Then Exit Function
        GetFileAssociation = "No association found!"
        E = String(260, Chr(0))
        i = FindExecutable(sFilepath, vbNullString, E)
        If i > 32 Then GetFileAssociation = Left(E, InStr(E, Chr(0)) - 1)
    End Function
    

    Thank you for your code, which isn't EXACTLY what I wanted, but can be adapted for me.

提交回复
热议问题