tiredofit
Well-known Member
- Joined
- Apr 11, 2013
- Messages
- 1,924
- Office Version
- 365
- 2019
- Platform
- Windows
If I understand this article correctly:
it claims the Workbook_BeforeClose event does NOT necessarily kick off code saved there.
Therefore this workaround has been suggested:
My question is why not simply do this?
Rich (BB code):
it claims the Workbook_BeforeClose event does NOT necessarily kick off code saved there.
Therefore this workaround has been suggested:
Rich (BB code):
Its true that if close Excel manually the IgnoreRemoteRequests setting reverts to what iwas on opening - but NOT if you close Excel programmatically (via Application.Quit).
The generic solution to the problem (of Workbook_BeforeClose ignoring some VBA commands if triggered by ActiveWindow.Close) is this:
a. write your own module-level procedure, eg My_WB_BeforeClose_Stuff()
b. declare a public boolean Excel_Exited_Manually and set its intial value to True
c. create a workbook-level event WorkBook_BeforeClose containing only
If Excel_Exited_Manually then My_WB_BeforeClose_Stuff
d. in your code wherever you use ActiveWindow.Close (or ThisWorkbook.Close) precede it with
My_WB_BeforeClose_Stuff
Excel_Exited_Manually = False
Then your single My_WB_BeforeCloseStuff code will work when the spreadsheet is closed manually or programmatically (eg via your own Exit button on a form or command-bar).
My question is why not simply do this?
Rich (BB code):
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Call My_WB_BeforeClose_Stuff
End Sub
Sub My_WB_BeforeClose_Stuff()
Application.IgnoreRemoteRequests = False
End Sub