OK, I see you use AcadDocument.Activate() event to run command "MenuBar" (to make the menu bar appear).
I also noticed that you removed some code from your original post (something related to reading data from Excel sheet?).
AcadDocument.Activate() event happens whenever a document becomes current active one, which is just as expected. However, it ALSO FIRES when the LAST DOCUMENT IS CLOSING, at that moment, while the ThisDrawing object is still available (e.g. not Nothing), but its functionality (properties/methods) has already become not accessible. You can verify it yourself with this code:
Option Explicit
Private Sub AcadDocument_Activate()
On Error Resume Next
MsgBox "Drawing name: " & ThisDrawing.Name & vbCrLf & _
"Document count: " & Application.Documents.Count
If Err.Number <> 0 Then
MsgBox "error: " & Err.Description
End If
End Sub
In AutoCAD, you open a couple of drawings and you would see the message box shows every time a new document is opened. Then you close each document and see the message box as well. When you close the last document, you still see the message box, but with the error message. meaning, the Activate event also fires when last drawing document closes.
So, I guess, in your case, once you have that Activate event handing code in place, whenever you close AutoCAD, you get VBA error, because of the reason I described.
From my code, as you can see, you can simply use On Error Resume Next to let last document to be closed without being stopped by the error.
However, I'd say doing one time work, such as showing menu bar, or loading data in this event every time is fires may not be a good choice: you do not need to run "MENUBAR" command each time a document is activated, and certainly may not need to load data from Excel each time a document is activated. You probably want to set a global/public variable as flag to indicate whether the work (showing menu bar, or load data from outside) having been done and so, you can use "If [done] then Exit" in the Activate event to bypass he work.