I have a large workbook with a lot of formulas and vba codes. When using a link to open…
- User
I have a large workbook with a lot of formulas and vba codes. When using a link to open a smaller different workbook, with the first and larger workbook still open, the formulas and vba codes in the smaller workbook run very slowly. While the smaller workbook is updating its own formulas, could it be forcing the larger workbook to update its own formulas too.
- Assistant
It is possible that the larger workbook is also being impacted by the smaller workbook's formulas and updates. When multiple workbooks are open and active, they can all affect each other's performance. This can be especially true if there are complex formulas and VBA codes involved. You may want to try closing any unnecessary workbooks and optimizing your formulas and codes to improve overall performance.
- User
With both workbooks open, is there a vba code that can be used on the active workbook to disable all events on the not active workbook
- Assistant
Yes, you can use the
Application.EnableEventsproperty to disable events on the workbook that is not active. Here is an example code snippet:Sub DisableEventsOnInactiveWorkbook() Dim wbActive As Workbook Dim wbNotActive As Workbook Set wbActive = ThisWorkbook Set wbNotActive = Workbooks("Name of Not Active Workbook.xlsx") Application.EnableEvents = False ' Disable Events wbNotActive.Sheets("Sheet1").Range("A1").Value = "New Value" ' Update value in the not active workbook Application.EnableEvents = True ' Enable Events End SubNote that this code updates a cell value in the not active workbook, but you can modify it to fit your needs. The key point is to use the
Application.EnableEventsproperty to disable events in the not active workbook before making any updates. - User
When the active workbook is closing, on the Workbook Close event, how can I re enable the events that I had been turned off or set to False
- Assistant
You can use the
WorkbookOpenevent to re-enable the events that you had turned off in theWorkbook_Closeevent.Here's an example of how you can do this:
In the
ThisWorkbookmodule, add the following code:Private Sub Workbook_Close() Application.EnableEvents = False 'Other code goes here End Sub Private Sub Workbook_Open() Application.EnableEvents = True End SubThis code turns off the events in the
Workbook_Closeevent and then turns them on again in theWorkbook_Openevent. This ensures that the events are re-enabled when the workbook is opened again.Make sure to replace
'Other code goes herewith any other code that you may have in yourWorkbook_Closeevent. - User
What about if I the close event on the active workbook is written as so, would it work:
- Assistant
If you have written your
Workbook_Closeevent like this:Private Sub Workbook_Close() Workbooks("Name of Not Active Workbook.xlsx").EnableEvents = True End SubThis code will not work as the syntax is incorrect. The
EnableEventsproperty is a property of theApplicationobject, not theWorkbookobject.To enable events on the not active workbook, you can modify the code like this:
Private Sub Workbook_Close() Application.EnableEvents = False 'disable the events on all workbooks Workbooks("Name of Not Active Workbook.xlsx").Activate 'activate the not active workbook Application.EnableEvents = True 'enable the events on the not active workbook End SubThis code will disable the events on all workbooks, activate the not active workbook, and then enable the events on the not active workbook before closing the active workbook. This ensures that the events are re-enabled on the not active workbook before the active workbook is closed.
Note that you need to replace
Name of Not Active Workbook.xlsxwith the actual name of the not active workbook that you want to enable the events for.