+ Reply to Thread
Results 1 to 3 of 3

ShellExecute problem

Hybrid View

  1. #1
    Registered User
    Join Date
    08-30-2011
    Location
    Belgrade
    MS-Off Ver
    Excel 2003, 2007
    Posts
    2

    ShellExecute problem

    Hello,

    I have a code I develop in Excel 2003. So it can work in 2003/2007/2010 Excels ...

    I have to open certain pdf, so I used ShellExecute ...

    I found this declaration on the web :
    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
    Calling is just
    ShellExecute 0, "Open", pdf_path_name, "", "", vbNormalNoFocus
    It works fine on my 32bit machine (Excel 2003, XP ...)

    How can I code it both for 32bit and 64bit machines ?

    Thanks in advance

  2. #2
    Forum Expert Colin Legg's Avatar
    Join Date
    03-30-2008
    Location
    UK
    MS-Off Ver
    365
    Posts
    1,256

    Re: ShellExecute problem

    Welcome to the forum.

    The 64 bit declaration would be:
    Private Declare PtrSafe Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" ( _
             ByVal hwnd As LongPtr, ByVal lpOperation As String, ByVal lpFile As String, _
             ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As LongPtr


    For compatability, you can use conditional compilation as follows:
    #If VBA7 Then
    
        Private Declare PtrSafe Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
            (ByVal hwnd As LongPtr, ByVal lpOperation As String, ByVal lpFile As String, _
            ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As LongPtr
    
     #Else
     
         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
    
     #End If



    [/code]
    Hope that helps,

    Colin

    RAD Excel Blog

  3. #3
    Registered User
    Join Date
    08-30-2011
    Location
    Belgrade
    MS-Off Ver
    Excel 2003, 2007
    Posts
    2

    Re: ShellExecute problem

    Thank you very much Colin.

    I copied the code, I can't test the VBA7 branch but I'm sure it would work.

    Thanks a lot.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1