0

I have an Excel spreadsheet someone else gave me. I ran it today for the first time in years and got the message about converting. I did a global search and replace to change all the Declare Function to Declare Function PtrSafe and every instance of Long to LongPtr. I've tried the search and replace setting for current module amd project. Is that correct and is there anything else I need to do?

Here are 2 pieces of the code (it's quite long so I hesitate to post it all here):

Private Declare Function PtrSafe OpenRRHelpFile 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 LongPtr) As LongPtr
Private Declare Function PtrSafe FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As LongPtr
Private Declare Function PtrSafe SetWindowLongPtr Lib "user32" Alias "SetWindowLongPtrA" (ByVal hwnd As LongPtr, ByVal nIndex As LongPtr, ByVal dwNewLongPtr As LongPtr) As LongPtr

and

    
    Dim objControl As Control
    Dim lCtlCnt As LongPtr
    
    mCancelEvent = False
    mReadOperation = False
    
    If mcolTextBoxes Is Nothing Then
        Set mcolTextBoxes = New Collection
    End If
    
    'Loop through all the controls
    For Each objControl In Me.Controls
        ' Look for text boxes only
        If TypeOf objControl Is MSForms.TextBox Then
            lCtlCnt = lCtlCnt + 1
            Set mTextBoxes = New clsXLControlHandlers
            'Tell it to handle the events for the text box
            mTextBoxes.Init objControl, Me
            'Add the event handler instance to our collection so it stays alive during the life of the workbook
            mcolTextBoxes.Add mTextBoxes
        End If
    Next objControl
    ' Reset object to destroy and clear memory
    Set objControl = Nothing
    
    'Release control so the system can update things that have occurred whilst the code is running
    DoEvents

    ' Set form formatting
    Me.Caption = "RESPA Escrow Calculator v3.0"
    Me.lblFormHeader = "Welcome " & Application.UserName & "!"
    ' Set focus on first field
    Me.mpDataInput.Value = 0
    'Call the method to load the months and years
    Call LoadMonthsAndYears(8)
    ' Set focus on first field
    Me.cboSelMonths.SetFocus
    ' Show the form at the top of other windows
    SetWindowLongPtr FindWindow("ThunderDFrame", Me.Caption), GWL_HWNDPARENT, ByVal 0&

End Sub
OutThere
  • 467
  • 2
  • 8
  • 19
  • 3
    _"I did a global search and replace to change all the Declare Function to Declare Function PtrSafe and every instance of Long to LongPtr"_ - that's _not_ how you're supposed to do it... – Dai Apr 24 '23 at 16:56
  • Could you explain how it should be done? I don't know much about VBA, I just need to make this spreadsheet work so I can get back to my job. – OutThere Apr 24 '23 at 17:39
  • 1
    Good overview here: https://codekabinett.com/rdumps.php?Lang=2&targetDoc=windows-api-declaration-vba-64-bit – Tim Williams Apr 24 '23 at 17:59
  • 3
    ...and your 3 required declarations are here: https://jkp-ads.com/articles/apideclarations.asp – Tim Williams Apr 24 '23 at 18:30
  • 1
    You find further helpful hints in post [Compatibility 32bit Excel and 64bit (Office365)](https://stackoverflow.com/questions/66797863/compatibility-32bit-excel-and-64-bit-excel-office-365/67284739#67284739) – T.M. Apr 24 '23 at 18:38

0 Answers0