Unable to use Application.OnTime to run Timer - Cannot run the macro....?

Pascal

Board Regular
Joined
Jun 6, 2007
Messages
200
Hi,

I'm getting the following message appear: -

Cannot run the macro "C:\Path\Workbook'!SubName'. The macro may not be available in the workbook or all macros may be disabled.

The code for the Timer I've taken from the link supplied in the following post http://www.mrexcel.com/forum/excel-questions/351089-how-do-i-make-macro-run-every-minute.html and I've used the example from Pearson Software Consulting

Here is the code I've got in my Module: -

Code:
Option Explicit

Public RunWhen As Double
Public Const cRunIntervalSeconds = 30
Public Const cRunWhat = "CheckLocation"

Sheet2 Code: -

Code:
Option Explicit

Dim strCurrSystem As String

Sub CheckLocation()

    strLogPath = Sheet3.Cells(3, 2)

    '* Inform User of Check
    lblInformation.Caption = "Establishing Current Location..."
    strCurrSystem = Location
    lblInformation.Caption = ""
    
    Sheet2.Cells(5, 2).Value = strCurrSystem
    
    Call StartTimer
    
End Sub
Sub StartTimer()
    
    RunWhen = Now + TimeSerial(0, 0, cRunIntervalSeconds)
    Application.OnTime RunWhen, cRunWhat, , True
    
End Sub

Sub StopTimer()

    On Error Resume Next
    Application.OnTime RunWhen, cRunWhat, , False
    
End Sub

I've tried various things in the Trust Center including checking "Enable all macros (not recommended; potentially dangerous code can run)" under Macro Settings, but the same message appears?

Have I missed something?

The method I'm using seems to be a very common with numerous examples on the internet, so I'm at a loss as to why I'm unable to get it to run.

Any help, assistance, thoughts or suggestions most welcome!

Thanks & Regards
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Put all the code in a standard module, not the Sheet2 class module. With that change, you'll have to qualify the lblInformation control with the sheet reference:
Code:
Sheet2.lblInformation.Caption = "Establishing Current Location..."
 
Upvote 0
The code should be in a regular module

Put all the code in a standard module, not the Sheet2 class module. With that change, you'll have to qualify the lblInformation control with the sheet reference:
Code:
Sheet2.lblInformation.Caption = "Establishing Current Location..."

Thanks you both very much.....

Clearly miss-read the example.

Working fine now.

Thanks once again.
 
Upvote 0

Forum statistics

Threads
1,215,497
Messages
6,125,155
Members
449,208
Latest member
emmac

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top