0

I am trying to get excel to run an update every XX seconds.

Sub StartTesting() 
       Call RunAll_ISP   'this call works 
End Sub

Sub macro_timer() 'This sub schedules next run in XX seconds.
    Dim ScanInterval
    ScanInterval = Format(ThisWorkbook.Sheets("Configuration").Range("B5").Value, "hh:mm:ss")
    Application.OnTime Now + TimeValue(ScanInterval), "RunAll_ISP", Schedule:=True  ' !this macro call throws error!
End Sub

If I run Start_testing macro, call works. If I run macro_timer macro, it waits desired number of seconds, and then throwsthis error:

Cannot run the macro "C:\location_of_file\filename.xlsm'!RunAll_ISP'. The macro may not be available in this workbook or all macros may be disabled

The settings for macros in the Trust center are set to "Enable VBA macros"

What am I doing wrong?

2
  • Where is the RunAll_ISP procedure located? Is it in a standard module? Is it declared Public? Commented Nov 5, 2021 at 12:17
  • All subs are in ThisWorkbook. Tried Public - made no difference Commented Nov 5, 2021 at 19:55

1 Answer 1

1

Your problem cannot be reproduced. This simple Example works. So since your procedure StartTesting worked that means macros are definitely enabled, so the only option left is that your macro RunAll_ISP does not exist (or wrongly named).

Option Explicit


Public Sub RunAll_ISP()
    MsgBox "I run"
End Sub


Public Sub CreateTimer()
    Application.OnTime Now + TimeValue("00:00:05"), "RunAll_ISP", Schedule:=True
End Sub
Sign up to request clarification or add additional context in comments.

4 Comments

I started with the blank book, and added the code above to it. However I got exactly the same result. Here is a screenshot: link. BTW I'm using Office 365
And here is the screenshot when running the RunAll_ISP : link
@Eki because you put the code in ThisWorkbook and not into a Module! Als I asked in my first comment the code needs to be inserted into a standard (non class) module. So add a module and move the code there and it will work.
Thank you very much ! adding the module and having code there did work. I need to read about it more. for anyone with the same issue, here is a screenshot how it supposed to look like: link

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.