Jaafar Tribak
Well-known Member
- Joined
- Dec 5, 2002
- Messages
- 9,779
- Office Version
- 2016
- Platform
- Windows
Hi dear members,
Let's assume there is a workbook project where an API timer (SetTimer) is started in the workbook open event... This timer is supposed to be running thoughout the life of the workbook until it is closed.
In the workbook before_close event, the timer is cancelled by calling the (KillTimer) API. This step in imperative because Excel crashes if the workbook is closed without properly cancelling the API timer.
Now the problem is that if the workbook is unsaved at the time of closing , Excel displays the usual prompt (Save,Don't Save,Cancel) and if the user happens to click on the cancel button, the workbook will remain open but now the timer is already cancelled which I don't want because, as I said, I need the timer to stay running until the workbook is actually really closed.
So maybe what I need is a way of knowing if the user has clicked the Cancel button and if so, restart the timer again.
I was thinking of replacing the beforeclose prompt with a userform containing similar buttons and execute code respectively according to which button was clicked but I find this approach rather messy.
I was wondering if there is a more self-contained way code-wise other than having to use a separate userform... Any ideas ?
Regards.
Let's assume there is a workbook project where an API timer (SetTimer) is started in the workbook open event... This timer is supposed to be running thoughout the life of the workbook until it is closed.
In the workbook before_close event, the timer is cancelled by calling the (KillTimer) API. This step in imperative because Excel crashes if the workbook is closed without properly cancelling the API timer.
Now the problem is that if the workbook is unsaved at the time of closing , Excel displays the usual prompt (Save,Don't Save,Cancel) and if the user happens to click on the cancel button, the workbook will remain open but now the timer is already cancelled which I don't want because, as I said, I need the timer to stay running until the workbook is actually really closed.
So maybe what I need is a way of knowing if the user has clicked the Cancel button and if so, restart the timer again.
I was thinking of replacing the beforeclose prompt with a userform containing similar buttons and execute code respectively according to which button was clicked but I find this approach rather messy.
I was wondering if there is a more self-contained way code-wise other than having to use a separate userform... Any ideas ?
Regards.