Open a PDF file from Solidworks via a macro

Hi all
I'm looking to open a PDF file (with a known location) via a macro run from Solidworks
I did some research and nothing conclusive
I find solutions from Excel but not from solidworks

Do you think this is possible?

Which order should I choose?

Thank you :wink:

Hello
On the one hand, you have to declare the function to use the default pdf opening program:

Private Declare PtrSafe 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

Then call it that:

ret = ShellExecute(0, "open", "nom de fichier", vbNullString, "répertoire de stockage", 1)

With ret being a variable of type long

2 Likes

Great thank you for your answer, it allowed me to move forward
I'm on the right track I think
Adobe opens but the file does not
I'm digging again :grinning:

Private Declare PtrSafe 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 main()

ret = ShellExecute(0, "open", "C:\Program Files\Adobe\Acrobat DC\Acrobat\Acrobat.exe", vbNullString, "U:\PLAN\01 PDF\USMEC000121-C.PDF", 1)

End Sub

Hello
Instead of " C:\Program Files\Adobe\Acrobat DC\Acrobat\Acrobat.exe ", " USMEC000121-C.PDF "
And instead of " U:\PLAN\01 PDF\USMEC000121-C.PDF " just "U:\PLAN\01 PDF\"

1 Like

I was almost there as well
thank you for your help :pray: :+1:

Private Declare PtrSafe 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 main()

ret = ShellExecute(0, "open", "USMEC000121-C.PDF", vbNullString, "U:\PLAN\01 PDF\", 1)

End Sub
1 Like