fred wu
fred wu

Reputation: 55

how to judge if the use closes the excel file with x button at right upper corner in VBA

My VBA application sometimes is shutdown because of Citrix time-out. And the normal close of the excel file is by clicking X button at the right upper corner. My question is if VBA can judge the excel file is closed by which method. I need to do the further operations according to the method of closing the excel file. Thanks!

@HackSlash , the excel is put into Citrix environment, which will be time out after 15 minutes. if Citrix is time out, the excel file will be shutdown without saving the content. Some users of the VBA will click the button then go away; when they are back, the excel file is shutdown by Citrix without saving. After the user read through the result of VBA, they will clear the content for the sake of security. So here, the scenario is if the excel is shutdown by Citrix abnormally, I want to save the result of VBA, so that the user can still see the result after they go back; if the excel is closed by clicking X at the right-upper corner, it means that these users has read through the result, all the contents should be cleared for the sake of security. Thanks!

Upvotes: 1

Views: 203

Answers (1)

RBarryYoung
RBarryYoung

Reputation: 56755

It depends on how Citrix is closing your Excel sessions (I am not familiar with it), but probably, Yes you can tell.

The trick is to catch the QueryClose event and then check the CloseMode parameter. A 0 means that it was closed by clicking the [X] on the windows control menu. Citrix is probably using reason 2 or 3.

However, be forewarned that Citrix may be killing the Excel process in such a way that that this event is not called (though other shutdown events may happen). You'll have to test it to be sure.

Upvotes: 1

Related Questions