Hello
This has been driving me mad for ages. I have a VBA macro in a 'main' workbook that loops through a series of workbooks. A workbook is opened, a macro is run from it, it is saved and closed, then the next workbook is opened. The macro runs fine, doing all it needs to do.
However, if, after running the macro, I then open one of the same workbooks (from another macro, from file open, or from explorer) excel crashes with "Microsoft Excel has stopped working ". This happens every time, it is not intermittent.
If I open other, unrelated excel files, I don't get the crash.
So, I'm imagining that something is not being completely closed / finished / cleared when the macro runs from the main workbook, or in the macro run from each of the workbooks that is opened in the loop.
Here is part of the code that deals with the opening and closing of the workbooks from the 'main' workbook:
The macro that is run from each opened workbook contains the following at the end (i.e. when finishing off the code):
I'm not sure if this is enough of the code to be able to identify any potential problems.
Any hints would be very gratefully received.
This has been driving me mad for ages. I have a VBA macro in a 'main' workbook that loops through a series of workbooks. A workbook is opened, a macro is run from it, it is saved and closed, then the next workbook is opened. The macro runs fine, doing all it needs to do.
However, if, after running the macro, I then open one of the same workbooks (from another macro, from file open, or from explorer) excel crashes with "Microsoft Excel has stopped working ". This happens every time, it is not intermittent.
If I open other, unrelated excel files, I don't get the crash.
So, I'm imagining that something is not being completely closed / finished / cleared when the macro runs from the main workbook, or in the macro run from each of the workbooks that is opened in the loop.
Here is part of the code that deals with the opening and closing of the workbooks from the 'main' workbook:
Code:
'...code
Workbooks.Open Filename:=theFile(K), UpdateLinks:=3
Set wbSpec = Workbooks(specFile(K, 1))
myFile = ActiveWorkbook.Name
Application.Calculation = xlCalculationAutomatic
wbSpec.Worksheets("Flow Indicators & Run Scenarios").Activate
Application.Run ("'" & myFile & "'" & "!AnyScenario.AnyScenario")
'CLOSE THE FILE
Application.CutCopyMode = False
wbSpec.Close SaveChanges:=True
'...further processing
'...code
Application.Calculation = xlCalculationAutomatic
StopTime = Time
elapsedTime = Round((StopTime - StartTime) * 24 * 60, 2)
wSheet.Range("N19").Value = elapsedTime
wSheet.Activate
Application.StatusBar = False
Application.ScreenUpdating = True
wbHome.Save
Set wSheet = Nothing
Set wbHome = Nothing
Set wbSpec = Nothing
End Sub
Code:
'...code
Application.CutCopyMode = False
Worksheets(mySheet).Activate
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
Set SummISheet = Nothing
Set SummSheet = Nothing
Set SummMinSheet = Nothing
Set SummMaxSheet = Nothing
Set hmSheet = Nothing
End Sub
Any hints would be very gratefully received.