user/auto (timer) close of workbook in a userform???

Teladianium

New Member
Joined
Apr 10, 2012
Messages
15
Hi all.<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
<o:p></o:p>
Any help on this would help relive my frustration.<o:p></o:p>
<o:p></o:p>
I am trying at have a self closing workbook after 20 minutes with a UserForm to offer saving options, but to still close (without saving) if no choice has been made.<o:p></o:p>
<o:p></o:p>
I have been playing around with different codes, and just now on to “do until”<o:p></o:p>
<o:p></o:p>
My main problem seems to be if one of the buttons are selected to close wookbook, the timer carries on and reopens the book to close it. Just now the buttons work but it no longer self closes :(<o:p></o:p>
<o:p></o:p>
<o:p></o:p>
Main Workbook:<o:p></o:p>
<o:p></o:p>
Private Sub Workbook_Open()<o:p></o:p>
Reset<o:p></o:p>
Sheets("HOME").Select<o:p></o:p>
Range("a1").Select<o:p></o:p>
dtmSchedule = Now + TimeValue("00:20:20")<o:p></o:p>
Application.OnTime dtmSchedule, "TimeOut"<o:p></o:p>
<o:p></o:p>
End Sub<o:p></o:p>
Private Sub Workbook_SheetActivate(ByVal Sh As Object)<o:p></o:p>
Reset<o:p></o:p>
End Sub<o:p></o:p>
<o:p></o:p>
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)<o:p></o:p>
Reset<o:p></o:p>
End Sub<o:p></o:p>
<o:p></o:p>
Private Sub Workbook_BeforeClose(Cancel As Boolean)<o:p></o:p>
On Error Resume Next<o:p></o:p>
Application.OnTime dtmSchedule, "TimeOut", , False<o:p></o:p>
End Sub
<o:p></o:p>
<o:p></o:p>
<o:p></o:p>
UserForm:
<o:p></o:p>
<o:p></o:p>
Private Sub Warningtoclose_Show()<o:p></o:p>
<o:p></o:p>
Quit_Click = False<o:p></o:p>
SaveandQuit = False<o:p></o:p>
BootTime = "00:00:00"<o:p></o:p>
Do Until BootTime > "00:00:11"<o:p></o:p>
BootTime = BootTime + TimeValue("00:00:01")<o:p></o:p>
If "Quit_Click" = True Or "SaveandQuit" = True Then Exit Sub<o:p></o:p>
If BootTime >= "00:00:10" Then Exit Do<o:p></o:p>
<?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" /><st1:place w:st="on">Loop</st1:place><o:p></o:p>
<o:p></o:p>
ThisWorkbook.Close<o:p></o:p>
<o:p></o:p>
End Sub<o:p></o:p>
<o:p></o:p>
Private Sub Quit_Click()<o:p></o:p>
<o:p></o:p>
ThisWorkbook.Close<o:p></o:p>
<o:p></o:p>
End Sub<o:p></o:p>
<o:p></o:p>
Private Sub SaveandQuit_Click()<o:p></o:p>
<o:p></o:p>
ActiveWorkbook.Save<o:p></o:p>
<o:p></o:p>
ThisWorkbook.Close<o:p></o:p>
<o:p></o:p>
End Sub
<o:p></o:p>
<o:p></o:p>
<o:p></o:p>
<o:p></o:p>
<o:p></o:p>
Module1:
<o:p></o:p>
Sub Reset()<o:p></o:p>
Static SchedSave<o:p></o:p>
If SchedSave <> 0 Then<o:p></o:p>
Application.OnTime SchedSave, "WarningMessage", , False<o:p></o:p>
End If<o:p></o:p>
SchedSave = Now + TimeValue("00:20:20")<o:p></o:p>
Application.OnTime SchedSave, "WarningMessage", , True<o:p></o:p>
End Sub<o:p></o:p>
<o:p></o:p>
<o:p></o:p>
Sub WarningMessage()<o:p></o:p>
<o:p></o:p>
Warningtoclose.Show<o:p></o:p>
<o:p></o:p>
End Sub
<o:p></o:p>
<o:p></o:p>
<o:p></o:p>
Module2:
<o:p></o:p>
Public dtmSchedule As Date<o:p></o:p>
Sub TimeOut()<o:p></o:p>
ThisWorkbook.Close<o:p></o:p>
End Sub
<o:p></o:p>
<o:p></o:p>
Module3:
<o:p></o:p>
Public dTime As Date<o:p></o:p>
<o:p></o:p>
Sub KillWarningtoclose()<o:p></o:p>
Unload.Warningtoclose<o:p></o:p>
ThisWorkbook.Close<o:p></o:p>
End Sub


Many Thanks
Teladianium
 
Or perhaps a stop to all macro on closing (when using the old code were the self close works, but if save and quit buttons are used the book reopens)<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
<o:p></o:p>
Any insight would be greatly appreciated<o:p></o:p>

Teladianium
 
Upvote 0

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top