1) Is there a way to do this?
2) Is there a way to have a cell call a macro every time
that it is executed? I wrote a macro that tries to save
current worksheet, and can make a cell that changes value
every 10 seconds (using second()), but I don't know how to
get the macro to be called by the cell.
put starttimer in the workbook open and put stoptimer in the workbook close
Regards Ron
Public RunWhen As Double
Public Const cRunIntervalSeconds = 10
Public Const cRunWhat = "The_Sub"
Sub StartTimer()
RunWhen = Now + TimeSerial(0, 0, cRunIntervalSeconds)
Application.OnTime earliesttime:=RunWhen, procedure:=cRunWhat, _
schedule:=True
End Sub
Sub The_Sub()
MsgBox ""
'
' your code here
'
StartTimer
End Sub
Sub StopTimer()
On Error Resume Next
Application.OnTime earliesttime:=RunWhen, _
procedure:=cRunWhat, schedule:=False
End Sub
"Christopher" <c...@d.com> schreef in bericht
news:25c301c108ac$3d1889e0$a5e62ecf@tkmsftngxa07...
Thanks for the help. Can I ask you to give a little
more information. I have only a very rudimentary
familiarity with visual basic and excel macros (but I am
fairly computer/programming savvy generally). I don't
know what starttimer or workbook open or close are or how
to go about doing this. Also, will this close and reopen
the workbook every time (as opposed to just saving it?).
Thanks,
Christopher
>.
>
When the workbook is closed the stoptimer sub is run to stop running the sub
every 10 seconds.
I hope you understand it, if not mail back.
Regards Ron
---------------------------------------------------------------------
Private Sub Workbook_BeforeClose(Cancel As Boolean)
StopTimer
End Sub
Private Sub Workbook_Open()
StartTimer
End Sub
put this two subs under thisworkbook in the VBA editor(alt- f11)
---------------------------------------------------------------
And copy and paste these subs in a normal module
Public RunWhen As Double
Public Const cRunIntervalSeconds = 10
Public Const cRunWhat = "The_Sub"
Sub StartTimer()
RunWhen = Now + TimeSerial(0, 0, cRunIntervalSeconds)
Application.OnTime earliesttime:=RunWhen, procedure:=cRunWhat, _
schedule:=True
End Sub
Sub The_Sub()
MsgBox ""
'
' your code here
'
StartTimer
End Sub
Sub StopTimer()
On Error Resume Next
Application.OnTime earliesttime:=RunWhen, _
procedure:=cRunWhat, schedule:=False
End Sub
---------------------------------------------------------
"Christopher" <c...@d.com> schreef in bericht
news:457901c108b2$fab01850$9ae62ecf@tkmsftngxa02...
Will save the workbook for you, put this in the sub that run every 10
seconds
Ron
"Ron de Bruin" <ronde...@kabelfoon.nl> schreef in bericht
news:OZiJVTLCBHA.1288@tkmsftngp02...