Hi,
i have 4 active X buttons on a sheet, all work okay apart from 1.
this is the code
Private Sub CommandButton1_Click() 
    Dim lParam As LongPtr 
    Dim lhWndP As LongPtr 
    
If GetHandleFromPartialCaption(lhWndP, "AudaEnterpriseGold") = True Then
EnumChildWindows lhWndP, AddressOf EnumChildProc, lParam
End If
End Sub
on clicking the button it causes Excel to crash and restart.

i have tried assigning the code to a sub and then call that from the button and it works ok

Private Sub CommandButton1_Click() 

RunGetDataFromWindows

End Sub
Sub RunGetDataFromWindows() 
    Dim lParam As LongPtr  
    Dim lhWndP As LongPtr 
    
If GetHandleFromPartialCaption(lhWndP, "AudaEnterpriseGold") = True Then
EnumChildWindows lhWndP, AddressOf EnumChildProc, lParam
End If

End Sub
Any ideas?
I have tried deleting the button and adding a new one but it still happens.