1

Topic: Application.onTime Repeatedly causes document discovery

Dobnyj day. All the day I grapple with this problem.
The essence in that most likely (I already at random understood it) after closing of the book method Application.onTime remains planned and again opens the document through time which to it is planned for performance of the function set to it. I overcame it in such a way

Private Sub Workbook_BeforeClose (Cancel As Boolean)
Application. OnTime cancelTime, "checkFile", False
End Sub

But it works (a file after closing does not open any more itself) only when close the book on a dagger and if to launch function - closeFile the file again opens after closing. I in  specific, after all in function runtime closeFile all the same  -

Private Sub Workbook_BeforeClose (Cancel As Boolean)
Application. OnTime cancelTime, "checkFile", False
End Sub

2

Re: Application.onTime Repeatedly causes document discovery

Found the decision.

Public cancelTime As Variant
Function closeFile ()
Workbooks. Application. DisplayAlerts = False
Application. OnTime cancelTime, "checkFile", False
Workbooks ("test.xlsm").Save
Workbooks ("test.xlsm").Close
End Function
Function checkFile ()
cancelTime = (Now + TimeValue ("0:00:05 AM"))
Application. OnTime cancelTime, "checkFile"
If IsHasFile ("C:\Users\vdekameron\Downloads\1.txt") = True Then
closeFile
End If
End Function
Function IsHasFile (Path As String) As Boolean
If Dir (Path) = "" Then
IsHasFile = False
Else
IsHasFile = True
End If
End Function