Teladianium
New Member
- Joined
- Apr 10, 2012
- Messages
- 15
Hi all.<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com
ffice
ffice" /><o
></o
>
<o
></o
>
Any help on this would help relive my frustration.<o
></o
>
<o
></o
>
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
></o
>
<o
></o
>
I have been playing around with different codes, and just now on to “do until”<o
></o
>
<o
></o
>
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
></o
>
<o
></o
>
<o
></o
>
Main Workbook:<o
></o
>
<o
></o
>
Private Sub Workbook_Open()<o
></o
>
Reset<o
></o
>
Sheets("HOME").Select<o
></o
>
Range("a1").Select<o
></o
>
dtmSchedule = Now + TimeValue("00:20:20")<o
></o
>
Application.OnTime dtmSchedule, "TimeOut"<o
></o
>
<o
></o
>
End Sub<o
></o
>
Private Sub Workbook_SheetActivate(ByVal Sh As Object)<o
></o
>
Reset<o
></o
>
End Sub<o
></o
>
<o
></o
>
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)<o
></o
>
Reset<o
></o
>
End Sub<o
></o
>
<o
></o
>
Private Sub Workbook_BeforeClose(Cancel As Boolean)<o
></o
>
On Error Resume Next<o
></o
>
Application.OnTime dtmSchedule, "TimeOut", , False<o
></o
>
End Sub
<o
></o
>
<o
></o
>
<o
></o
>
UserForm:
<o
></o
>
<o
></o
>
Private Sub Warningtoclose_Show()<o
></o
>
<o
></o
>
Quit_Click = False<o
></o
>
SaveandQuit = False<o
></o
>
BootTime = "00:00:00"<o
></o
>
Do Until BootTime > "00:00:11"<o
></o
>
BootTime = BootTime + TimeValue("00:00:01")<o
></o
>
If "Quit_Click" = True Or "SaveandQuit" = True Then Exit Sub<o
></o
>
If BootTime >= "00:00:10" Then Exit Do<o
></o
>
<?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com
ffice:smarttags" /><st1
lace w:st="on">Loop</st1
lace><o
></o
>
<o
></o
>
ThisWorkbook.Close<o
></o
>
<o
></o
>
End Sub<o
></o
>
<o
></o
>
Private Sub Quit_Click()<o
></o
>
<o
></o
>
ThisWorkbook.Close<o
></o
>
<o
></o
>
End Sub<o
></o
>
<o
></o
>
Private Sub SaveandQuit_Click()<o
></o
>
<o
></o
>
ActiveWorkbook.Save<o
></o
>
<o
></o
>
ThisWorkbook.Close<o
></o
>
<o
></o
>
End Sub
<o
></o
>
<o
></o
>
<o
></o
>
<o
></o
>
<o
></o
>
Module1:
<o
></o
>
Sub Reset()<o
></o
>
Static SchedSave<o
></o
>
If SchedSave <> 0 Then<o
></o
>
Application.OnTime SchedSave, "WarningMessage", , False<o
></o
>
End If<o
></o
>
SchedSave = Now + TimeValue("00:20:20")<o
></o
>
Application.OnTime SchedSave, "WarningMessage", , True<o
></o
>
End Sub<o
></o
>
<o
></o
>
<o
></o
>
Sub WarningMessage()<o
></o
>
<o
></o
>
Warningtoclose.Show<o
></o
>
<o
></o
>
End Sub
<o
></o
>
<o
></o
>
<o
></o
>
Module2:
<o
></o
>
Public dtmSchedule As Date<o
></o
>
Sub TimeOut()<o
></o
>
ThisWorkbook.Close<o
></o
>
End Sub
<o
></o
>
<o
></o
>
Module3:
<o
></o
>
Public dTime As Date<o
></o
>
<o
></o
>
Sub KillWarningtoclose()<o
></o
>
Unload.Warningtoclose<o
></o
>
ThisWorkbook.Close<o
></o
>
End Sub
Many Thanks
Teladianium




<o


Any help on this would help relive my frustration.<o


<o


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


<o


I have been playing around with different codes, and just now on to “do until”<o


<o


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


<o


Main Workbook:<o


<o


Private Sub Workbook_Open()<o


Reset<o


Sheets("HOME").Select<o


Range("a1").Select<o


dtmSchedule = Now + TimeValue("00:20:20")<o


Application.OnTime dtmSchedule, "TimeOut"<o


<o


End Sub<o


Private Sub Workbook_SheetActivate(ByVal Sh As Object)<o


Reset<o


End Sub<o


<o


Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)<o


Reset<o


End Sub<o


<o


Private Sub Workbook_BeforeClose(Cancel As Boolean)<o


On Error Resume Next<o


Application.OnTime dtmSchedule, "TimeOut", , False<o


End Sub
<o


<o


<o


UserForm:
<o


<o


Private Sub Warningtoclose_Show()<o


<o


Quit_Click = False<o


SaveandQuit = False<o


BootTime = "00:00:00"<o


Do Until BootTime > "00:00:11"<o


BootTime = BootTime + TimeValue("00:00:01")<o


If "Quit_Click" = True Or "SaveandQuit" = True Then Exit Sub<o


If BootTime >= "00:00:10" Then Exit Do<o


<?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com





<o


ThisWorkbook.Close<o


<o


End Sub<o


<o


Private Sub Quit_Click()<o


<o


ThisWorkbook.Close<o


<o


End Sub<o


<o


Private Sub SaveandQuit_Click()<o


<o


ActiveWorkbook.Save<o


<o


ThisWorkbook.Close<o


<o


End Sub
<o


<o


<o


<o


<o


Module1:
<o


Sub Reset()<o


Static SchedSave<o


If SchedSave <> 0 Then<o


Application.OnTime SchedSave, "WarningMessage", , False<o


End If<o


SchedSave = Now + TimeValue("00:20:20")<o


Application.OnTime SchedSave, "WarningMessage", , True<o


End Sub<o


<o


<o


Sub WarningMessage()<o


<o


Warningtoclose.Show<o


<o


End Sub
<o


<o


<o


Module2:
<o


Public dtmSchedule As Date<o


Sub TimeOut()<o


ThisWorkbook.Close<o


End Sub
<o


<o


Module3:
<o


Public dTime As Date<o


<o


Sub KillWarningtoclose()<o


Unload.Warningtoclose<o


ThisWorkbook.Close<o


End Sub
Many Thanks
Teladianium