Hi there, I got the following macro that runs a macro every minute from the top of the hour. I have difficulty making it stop running when I close the sheet.
Sub ActivateOnTime()
Dim T, When
T = Now()
When = TimeValue(Hour(T) & ":" & Minute(T) + (1 - (Minute(T) Mod 1)) & ":00") ' this will calculate the next number that is divisible by 1
Application.OnTime When, "MyMacro"
End Sub
Sub MyMacro()
'your code here
ActivateOnTime
End Sub
I get the following error when I put this code in 'ThisWorkbook:
Private Sub Workbook_beforeclose(cancel As Boolean)
Application.OnTime When, , , Schedule:=False
End Sub
Error:
Run-time error '1004:
Method 'Ontime' of object '_Application' failed
What should I put in ThisWorkbook to make the Application.Ontime stop from running every minute?
Thanks
Sub ActivateOnTime()
Dim T, When
T = Now()
When = TimeValue(Hour(T) & ":" & Minute(T) + (1 - (Minute(T) Mod 1)) & ":00") ' this will calculate the next number that is divisible by 1
Application.OnTime When, "MyMacro"
End Sub
Sub MyMacro()
'your code here
ActivateOnTime
End Sub
I get the following error when I put this code in 'ThisWorkbook:
Private Sub Workbook_beforeclose(cancel As Boolean)
Application.OnTime When, , , Schedule:=False
End Sub
Error:
Run-time error '1004:
Method 'Ontime' of object '_Application' failed
What should I put in ThisWorkbook to make the Application.Ontime stop from running every minute?
Thanks