sassriverrat
Well-known Member
- Joined
- Oct 4, 2018
- Messages
- 655
I have the code below in a workbook. When I close the workbook, it typically kills all other open workbooks of excel. However, excel has started opening a blank window (no loaded workbook) in a second window whenever opening any excel file. Anybody have ideas on both of these. Further, sometimes when closing the workbook, it'll kick an error that I can't trace- the error message pops up and then when I hit debug, it's gone. I've tried removing the On Error section of code but to no avail.
Code:
Private Sub Workbook_BeforeClose(cancel As Boolean)On Error GoTo Helper
'This is the last event to run as Excel is closing
Sheets("Notes").Visible = xlVeryHidden
Sheets("Developer").Visible = xlVeryHidden
'Kills Noon/Arrival Sheets to Preserve Template
If ActiveWorkbook.name = "Master Voyage Report.xlsm" Then
Application.DisplayAlerts = False
Sheets("Developer").Range("A2:D3,A5:D5,A7:D7").ClearContents
For Each sh In ThisWorkbook.Worksheets
If LCase(sh.name) Like "noon*" Then
If Len(sh.name) > 4 Then
If IsNumeric(Mid(sh.name, 5, Len(sh.name))) Then sh.Delete
Else
sh.Delete
End If
End If
Next
If SheetExists("Arrival") Then
Sheets("Arrival").Delete
End If
If SheetExists("Voyage Specifics") Then
Sheets("Voyage Specifics").Delete
End If
Else: Sheets("Ports").Visible = xlVeryHidden
End If
Application.DisplayAlerts = True
ActiveWorkbook.Save
'Error Clearing Code
Exit Sub
Helper:
resp = MsgBox("We're sorry to see you've encountered an error." & vbCrLf & vbCrLf & "To proceed, we recommend you contact the Developer " & _
"with error codes [1014] and " & "[" & Err.Number & "-" & Err.Description & "]." & vbCrLf & vbCrLf & "To attempt to patch your problem at least " & _
"temporarily, we recommend you click [Yes] to see help directions. Would you like to continue?", vbYesNoCancel, name)
If resp = vbYes Then
Call Error_Handle(sprocname, Err.Number, Err.Description)
ElseIf resp = vbNo Then
Exit Sub
ElseIf resp = vbCancel Then
Exit Sub
End If
End Sub