Run something once per session

User avatar
ErikJan
BronzeLounger
Posts: 1254
Joined: 03 Feb 2010, 19:59
Location: Terneuzen, the Netherlands

Run something once per session

Post by ErikJan »

In code (probably Auto_Open) I want to check something when the sheet is loaded. After that is done, I DO NOT want to do that check again until the sheet loads again (I don't care if Excel itself is closed as well or not).
Reason is that I need to know in which rows a certain setting is saved on disk with the sheet and after loading, my code could change some of that.
So this should survive a state loss and a user running Auto_Open manually.

Hope this is a bit clear; basically I must be sure that certain information is actually saved on disk before I can mark it as processed.

User avatar
HansV
Administrator
Posts: 78540
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Run something once per session

Post by HansV »

You might use the Workbook_Open event procedure in the ThisWorkbook module.
Theoretically, a user could start this procedure, but that is not very likely, since it is not listed in the Macros dialog. If you protect the VBA project, users cannot view ThisWorkbook, making it even more improbable.
Best wishes,
Hans

User avatar
ErikJan
BronzeLounger
Posts: 1254
Joined: 03 Feb 2010, 19:59
Location: Terneuzen, the Netherlands

Re: Run something once per session

Post by ErikJan »

OK, makes sense. I'll try that. Thanks Hans