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