That self-closing MsgBox is not reliable, as you discovered.
Better to display a userform and then close it after x seconds.
--
Jim Cone
Portland, Oregon USA
http://www.contextures.com/excel-sort-addin.html
..
..
"Robert Richie" <
[email protected]>
wrote in message I have this code copied exactly as below but when the prompt comes up if you leave it idle and do not check anything the document
does not close is there something else i need to add or do i have an error in my coding?
Thanks
Robert
Option Explicit
Option Compare Text
Private RunWhen As Double
Private Const C_TEST_OPEN_SECONDS = 60
Private Sub Workbook_BeforeClose(Cancel As Boolean)
On Error Resume Next
Application.OnTime RunWhen, "ThisWorkbook.CloseMe", , False
End Sub
Private Sub Workbook_Open()
RunWhen = Now + TimeSerial(0, 0, C_TEST_OPEN_SECONDS)
Application.OnTime RunWhen, "ThisWorkbook.CloseMe", , True
End Sub
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
On Error Resume Next
Application.OnTime RunWhen, "ThisWorkbook.CloseMe", , False
RunWhen = Now + TimeSerial(0, 0, C_TEST_OPEN_SECONDS)
Application.OnTime RunWhen, "ThisWorkbook.CloseMe", , True
End Sub
Public Sub CloseMe()
Dim IWSH As IWshRuntimeLibrary.WshShell
Dim Res As Long
Set IWSH = New IWshRuntimeLibrary.WshShell
Res = IWSH.Popup(Text:="This Work Will Close so that Others Can use it. Do you Need To Keep open?", _
secondstowait:=3, Type:=vbYesNo + vbDefaultButton2)
If (Res = -1) Or (Res = vbNo) Then
On Error Resume Next
Application.OnTime RunWhen, "ThisWorkbook.CloseMe", , False
Me.Close savechanges:=True
End If
RunWhen = Now + TimeSerial(0, 0, C_TEST_OPEN_SECONDS)
Application.OnTime RunWhen, "ThisWorkbook.CloseMe", , True