Why does this crash

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

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
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
The code you posted is incomplete ... have you tried isolating where the crashing occurs by removing/commenting out the lines that you suspect are causing the problem ?
 
Upvote 0

Forum statistics

Threads
1,217,414
Messages
6,136,493
Members
450,016
Latest member
murarj

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top