Ontime questions

B

BruceJ

I am trying to get an ontime routine working.
Here are my questions...
Will it only run MACROS? or can it run a sub function
Where do I decalre the PUBLIC varibles


I tried to following in one of the modules (a_publicStuff):

Public NextTime As Double 'to setup 15 minute time
Public Const cRunIntervalSeconds = 900 ' 15 minutes
Public Const cRunWhat = "settimer_Click"

(if I put the above in my usercode area, the last two turn red)

and the following is in my userform code area.
Sub StartTimer()

'RunWhen = NextTime
Application.OnTime earliesttime:=NextTime, procedure:=cRunWhat, _
schedule:=True

End Sub

Sub settimer_Click()
MsgBox Format(Application.RoundUp(Time * 96, 0) / 96, "hh:mm:ss")
NextTime = NextTime + cRunIntervalSeconds
MsgBox cRunIntervalSeconds

MsgBox Format(NextTime, "hh:mm:ss")


End Sub

When I run my form, I get an error saying the macro can not be found.
If I create a macro with the name, it functions, but the nexttime does not
get incremented, and cRunIntervalSeconds is 0:00

Thanks
Bruce
 
C

Chip Pearson

Bruce,

You can't run procedures in a class module, only procedures in a standard
code module. Moreover, you can't declare Public constants in a class module
(which includes regular class modules, the ThisWorkbook module, sheet code
modules, and userform code modules). Declare everything in a standard code
module.

--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com (e-mail address removed)
 
B

BruceJ

Chip,

How do I declare in a "standard code module"?

What is the differance between a class and standard? I now this is probably
very basic to most people here, but....

Thanks
Bruce
 
C

Chip Pearson

Bruce,

In VBA, go to the Insert menu and choose Module. Put the code in that
module.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com (e-mail address removed)
 
B

BruceJ

Thaks!
Is there a way I can tell if an existing module is standard or class?

Thanks
Bruce
 
T

Tom Ogilvy

by default if should have a name like module1 if it is a standard module

It will be listed in the project explorer in the VB Editor under the entry
for modules under you workbook/project.

If it is a class module it would be under Class. Any other type class
module would not be listed as it is part of a sheet, thisworkbook or
userform.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top