Hi everyone,
I'm relatively new to VBA and was looking for a way to repeat an action in a spreadsheet. I stumbled across the Application.OnTime procedure and thought I'd give it a go.
I tried a piece of code I want to run when a workbook is opened and closed. I got the code to run on opening the workbook and at regular 5 minute intervals but when the workbook is closed, it throws up a Run-time error ‘1004’: Method ‘OnTime’ of object’_Application’ failed. The code is posted below.
Private Sub Workbook_Open()
Application.OnTime NextUpdate, "TimRun" , , True
End Sub
Public Sub TimRun()
MsgBox "Sheet Updated!", vbOKOnly, "Hello"
NextUpdate = Now + TimeValue("00:05:00")
Application.OnTime NextUpdate, "TimRun"
End Sub
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Application.OnTime NextUpdate, "TimRun", , False
MsgBox "Are you sure you want to close this workbook?", vbYesNo, "Hello"
End Sub
Any help would be most welcome.
Bookmarks