Hi there,

I have a long string of macros that have to run when a workbook is opened. There are updates happening during this process that involves opening other workbooks.

In implementing the 'Application.EnableCancelKey = xlDisabled' when holding down the ESC key while this string of macros runs, the code can be interrupted anywhere there is a workbook being opened and also when a workbook is being saved (as updates are taking place along the way).

Two workbooks are attached the demonstrate this. The code in 'Book1.xlsm' is as follows:
Sub test()

    Dim i As Long
    
    Application.EnableCancelKey = xlDisabled
    
    For i = 1 To 100000
        Cells(i, 1) = "10000"
    Next
    
    Workbooks.Open Filename:=ThisWorkbook.Path & "\Book2.xlsx"
        
    Workbooks("Book1.xlsm").Sheets("Sheet1").Activate
    
    For i = 1 To 100000
        Cells(i, 1) = "22222"
    Next

    Workbooks("Book2.xlsx").Close
    
End Sub
With the code as is, pressing and holding down the ESC key after execution will bring it to a stop at the end of the first loop where the 2nd workbook is being opened. If the line of code that opens the 2nd workbook is commented out and the same process is followed, both loops will complete even though the ESC key is pressed and held down.

Is there a way to prevent this from happening?

Thank you for any input.

TV
Book1.xlsmBook2.xlsx