Forum Discussion
perkin_warbeck
Mar 08, 2024Brass Contributor
When is it advisable to quit and restart Excel?
I have a VBA application which I develop on Windows and test it thoroughly there. I then I transfer the application to Mac for testing. Sometimes, on Mac, I'll get random OVERFLOW errors at trivial assignments, for example:
```
Dim x as Double
x = 72
```
If I single step in the Debugger, the overflow does not occur. But if I let the code run, it quickly hits another Overflow at some other equally-trivial assignment.
Closing the workbook without saving and reopening it does not solve the problem. However if I quit Excel and then open the workbook, the overflows do not happen.
How is closing a workbook and reopening it different from quitting Excel and then opening the workbook? Is it a good idea to quit Excel after I'm done using it?
- NikolinoDEGold Contributor
The VBA command you provided, which is simply quitting Excel, is not directly available in Excel for Mac using VBA, so far I know. Unlike Windows, Excel for Mac does not support directly quitting the application through VBA code. However, you can achieve a similar result by closing all open workbooks. Here's how you can do it:
Vba code is untested, please backup your file first.
Sub QuitExcelOnMac() Dim wb As Workbook ' Close all open workbooks except for the add-in workbooks For Each wb In Application.Workbooks If Not wb.IsAddin Then wb.Close False End If Next wb ' Quit Excel (last workbook should be closed) Application.Quit End Sub
This VBA code will close all open workbooks (excluding add-in workbooks) and then quit Excel. While it's not a direct "quit" command like in Windows, it achieves the same result by closing all workbooks and exiting the application. This approach should work effectively in Excel for Mac.
The text was created with the help of AI.
My answers are voluntary and without guarantee!
Hope this will help you.
Was the answer useful? Mark as best response and like it!
This will help all forum participants.
- perkin_warbeckBrass Contributor
Thank you for sharing your code, but I wasn't looking for an automated solution. I'll simply advise Mac users to quit Excel at the end of the day, rather than just closing their workbooks. If you only close the workbooks, but Excel is still running, it continues to consume resources. I'm testing on a Mac Mini with only 16GB memory, so that may be why the overflows are only happening to me.