none
UPDATE CODE FOR 64 vs 32 BIT RRS feed

  • Question

  • installing app on new 64 bit system. getting an error with the following code! any thoughts on what I need to do??

    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
    Private Const SW_SHOWMAXIMIZED As Long = 3
    Private Const SW_SHOWNORMAL As Long = 1
    Sub OpenFile(Filename As String)
        If ShellExecute(Application.hwnd, "Open", _
            Filename, 0&, 0&, SW_SHOWNORMAL) < 33 Then
            MsgBox "NO FILES FOUND", vbInformation
        End If
    End Sub

     

    thanks

    Doug

    Monday, December 30, 2019 1:58 PM

Answers

  •  found the answer

    had to add ptrsafe to my declaration

    thanks

    Doug

     

    • Marked as answer by 6da4 Monday, December 30, 2019 2:16 PM
    Monday, December 30, 2019 2:16 PM
  • Doug,
    re:  changes for 64 bit

    From:  http://www.jkp-ads.com/articles/apideclarations.asp

    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

    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

    '---


    Excel programs (now free) at MediaFire...
    The Custom_Functions add-in has 20 new Excel functions including the vLookUpAny function

    • Marked as answer by 6da4 Monday, December 30, 2019 2:53 PM
    Monday, December 30, 2019 2:17 PM

All replies

  •  found the answer

    had to add ptrsafe to my declaration

    thanks

    Doug

     

    • Marked as answer by 6da4 Monday, December 30, 2019 2:16 PM
    Monday, December 30, 2019 2:16 PM
  • Doug,
    re:  changes for 64 bit

    From:  http://www.jkp-ads.com/articles/apideclarations.asp

    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

    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

    '---


    Excel programs (now free) at MediaFire...
    The Custom_Functions add-in has 20 new Excel functions including the vLookUpAny function

    • Marked as answer by 6da4 Monday, December 30, 2019 2:53 PM
    Monday, December 30, 2019 2:17 PM
  • just a question...tested on a 32 bit system and seems to work fine. I assume this with work with 32 & 64 bit systems without issue?

    Monday, December 30, 2019 3:45 PM
  • Doug,
    re:  32 vs.64 bit

    64 bit and VBA7 were introduced with the xl2010 version.
    VBA prior to VBA7 won't recognize the LongPtr versions.
    So if you don't control who/what uses your code, then Conditional Compile will handle it...
    '---
    #If VBA7 then
      'declaration
    #Else
      'declaration
    #End If

    '---
    The above structure must be followed; no one liners or an elseif  works.

    Monday, December 30, 2019 4:18 PM
  • only have one user with xl2010 and he is upgrading soon, everyone else is xl2016. should be okay but thanks for the info - will do a little more research on this topic as time permits.

    thanks

    Doug

    Monday, December 30, 2019 4:31 PM