I am having an issue with Excel 2013 crashing where I have a master file that generates a new workbook from selected sheets from the master file.
the scenario is I create the new workbook with the selected or grouped sheets from the master file, it saves and closes the new workbook automatically. Now if I open the newly generated workbook, close it, and try and generate another one from the master file, Excel crashes.
Basically put, I can't run the code below, open the newly generated excel file, close it, run the code again.
If I run the code, open the newly generated excel file, close the newly generated excel file, close the master file, reopen the master file, then it doesn't crash >> this is what leads me to believe it has to do something with a tmp file.
parts of this code you can ignore as the initial part I am selecting or "grouping" the sheets based on tab color
the scenario is I create the new workbook with the selected or grouped sheets from the master file, it saves and closes the new workbook automatically. Now if I open the newly generated workbook, close it, and try and generate another one from the master file, Excel crashes.
Basically put, I can't run the code below, open the newly generated excel file, close it, run the code again.
If I run the code, open the newly generated excel file, close the newly generated excel file, close the master file, reopen the master file, then it doesn't crash >> this is what leads me to believe it has to do something with a tmp file.
parts of this code you can ignore as the initial part I am selecting or "grouping" the sheets based on tab color
Code:
Sub v2()
Dim iWorkbook, eWorkbook As Workbook
Set iWorkbook = ThisWorkbook
Dim iSheet As Worksheet
Dim iMark As Boolean
Dim x, i As Integer
Dim iCarrier, cell As Range
Set iCarrier = ThisWorkbook.Worksheets("Instructions").Range("C61:C65")
Application.AskToUpdateLinks = False: Application.DisplayAlerts = False: Application.ScreenUpdating = False: Application.DisplayStatusBar = True: Application.EnableEvents = False
For Each cell In iCarrier
DoEvents
Application.StatusBar = cell.Value
If cell.Value <> "" Then
For i = 1 To iWorkbook.Worksheets.Count
If iWorkbook.Worksheets(i).Visible Then
If iWorkbook.Worksheets(i).Tab.Color = RGB(99, 102, 106) Or iWorkbook.Worksheets(i).Tab.Color = RGB(0, 160, 210) Or iWorkbook.Worksheets(i).Tab.Color = RGB(112, 32, 130) _
Or iWorkbook.Worksheets(i).Tab.Color = RGB(234, 199, 241) Or iWorkbook.Worksheets(i).Tab.Color = RGB(213, 142, 227) Or iWorkbook.Worksheets(i).Tab.Color = RGB(84, 24, 97) _
Or iWorkbook.Worksheets(i).Tab.Color = RGB(56, 16, 65) Or iWorkbook.Worksheets(i).Tab.Color = RGB(0, 112, 192) Or iWorkbook.Worksheets(i).Tab.Color = RGB(0, 32, 96) Then
Worksheets(i).Select Not iMark
iMark = True
End If
End If
Next
ActiveWindow.SelectedSheets.Copy
Set eWorkbook = ActiveWorkbook
eWorkbook.SaveAs Filename:=ThisWorkbook.Path & Application.PathSeparator & cell.Value & "_Import.xlsx", FileFormat:=xlOpenXMLWorkbook
eWorkbook.Close
end sub