Roderick_E
Well-known Member
- Joined
- Oct 13, 2007
- Messages
- 2,051
I am running a subroutine on two 64bit machines both with Excel 2016 yet on one my program crashes entire Excel at launch with no error message. Here is the code (other code follows but it has to happen here).
Any ideas? Thanks
Any ideas? Thanks
Code:
Option Compare Text 'ignore text case
Option Explicit
'Object variable to trigger application events
Private WithEvents XLApp As Excel.Application
[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=If]#If[/URL] VBA7 Then
Dim mXLHwnd As LongPtr 'Excel's window handle
Dim mhwndForm As LongPtr 'The userform's window handle
Private Declare PtrSafe Function FindWindowA Lib "user32" (ByVal lpClassName As String, ByVal lpWindowName As String) As LongPtr
[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=If]#If[/URL] Win64 Then
Private Declare PtrSafe Function SetWindowLongA Lib "user32" Alias "SetWindowLongPtrA" (ByVal hwnd As LongPtr, ByVal nIndex As LongPtr, ByVal dwNewLong As LongPtr) As LongPtr
[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=Else]#Else[/URL]
Private Declare PtrSafe Function SetWindowLongA Lib "user32" (ByVal hwnd As LongPtr, ByVal nIndex As LongPtr, ByVal dwNewLong As LongPtr) As LongPtr
[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=End]#End[/URL] If
Private Declare PtrSafe Function SetForegroundWindow Lib "user32" (ByVal hwnd As LongPtr) As Long
[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=Else]#Else[/URL]
Dim mXLHwnd As Long 'Excel's window handle
Dim mhwndForm As Long 'The userform's window handle
Private Declare Function FindWindowA Lib "user32" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SetWindowLongA Lib "user32" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=End]#End[/URL] If
Const GWL_HWNDPARENT As Long = -8
Code:
Sub showxlst()
Dim frm As UserForm
Dim i As Long, x As Long, str As String, lname As String, cCtrl As Variant
Dim hit As Long
Dim cnt As Long
Dim strarray As String
Dim strunbound() As String
Dim xlstconfigs As Worksheet
Dim lastrow As Long
Dim rng1 As String
Dim rng2 As String
Dim rng3 As String
Dim tempForm As Object
Dim formstr As String
Dim c As Object
'Re-enable
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
Application.EnableEvents = True
Application.DisplayAlerts = True
Application.AskToUpdateLinks = True
Application.StatusBar = False
On Error Resume Next
For Each c In ThisWorkbook.VBProject.VBComponents
If c.Type = 3 Then
If InStr(c.Name, "xlst") > 0 And Len(c.Name) > 4 Then
formstr = c.Name
End If
If formstr <> "" Then
ThisWorkbook.VBProject.VBComponents("xlst").Name = "oldform"
ThisWorkbook.VBProject.VBComponents(formstr).Name = "xlst"
End If
End If
Next
If formstr <> "" Then
With ThisWorkbook.VBProject
.VBComponents.Remove .VBComponents("oldform")
End With
MsgBox "XLSuperTool updated", vbInformation, "ATTENTION"
Exit Sub
End If
Resume Next
.... more code here....
end sub