PDA

View Full Version : Excel Workbook ReOpening After Closing With Application.OnTime



leopaulc
12-04-2012, 11:02 AM
Dear All ,
I am using the below macro to close the workbook after crossing the time limit.
In workbook, i pasted the below one


Private Sub Workbook_Open()
Application.OnTime Now + TimeValue("00:03:00"), "close1_Me"
End Sub

and in the module,
Sub close_me()
ThisWorkbook.Close Savechanges:=True
End Sub

Sub close1_me()

Dim objWsh As Object, msg As String
Const Delay As Long = 3 'secs ?
Const wButtons As Long = 16 ' Boutons + icon

Set objWsh = CreateObject("WScript.Shell")
msg = "Please update the file. The file will close within 10 sec."

objWsh.Popup msg, Delay, "Reminder !!!!!!!!", wButtons
Application.OnTime Now + TimeValue("00:00:10"), "close_Me"

Set objWsh = Nothing

End Sub

Now the problem is, if i am clossing before 3 mins (before time limit), it opens the file and asks for the clossure.
The same repeats sometimes till i close all the workbook which is opened earlier.
If it is clossing normally, there is no error or loop is appeared.

Please help..

Regards,
Leo Paul

Excel Fox
12-04-2012, 12:00 PM
Hi LeoPaulC,

Please wrap your code using Code Tags. I have added the same for you this time.
Try


Sub close_me()
On Error Resume Next
Application.OnTime Now(), "close1_Me", , False
On Error GoTo 0
ThisWorkbook.Close Savechanges:=True
End Sub

leopaulc
12-04-2012, 02:05 PM
Dear Administrator,

Thank you for the guidance which i am receiving every time

regards,
Leo Paul