#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 61
Default On Time

I am using On Time routine from Chip Pearsons site as Follows:

Public RunWhen As Double
Public Const cRunIntervalSeconds = 30
Public Const cRUnWhat = "Macro2"

Sub StartTimer()
RunWhen = Now + TimeSerial(0, 0, cRunIntervalSeconds)
Application.OnTime earlisttime = RunWhen, procedu=cRUnWhat, schedule:=True
End Sub


Sub Macro2()

My code

StartTimer

End Sub


Where do I sore the code and how do I actually start the procedure/
Thanks!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default On Time

In the vbe with our workbook as the active project,
Insert=Module

Place it there

To start it, in the project explorer in the vbe, select the ThisWorkbook
entry. In the dropdowns at the top, select workbook on the left and Open on
the right.
Private Sub Workbook_Open
StartTimer
' or if you want to run you code on opening
'Macro2
End Sub

--
Regards,
Tom Ogilvy

"Henry" wrote in message
...
I am using On Time routine from Chip Pearsons site as Follows:

Public RunWhen As Double
Public Const cRunIntervalSeconds = 30
Public Const cRUnWhat = "Macro2"

Sub StartTimer()
RunWhen = Now + TimeSerial(0, 0, cRunIntervalSeconds)
Application.OnTime earlisttime = RunWhen, procedu=cRUnWhat,

schedule:=True
End Sub


Sub Macro2()

My code

StartTimer

End Sub


Where do I sore the code and how do I actually start the procedure/
Thanks!



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default On Time

You don't start the timer in the ontime procedure, you start it outside. The
OnTime will run that procedure after the specified delay.

Public RunWhen As Double
Public Const cRunIntervalSeconds = 30
Public Const cRUnWhat = "Macro2"

Sub Invokee()
StartTimer
End Sub

Sub StartTimer()
RunWhen = Now + TimeSerial(0, 0, cRunIntervalSeconds)
Application.OnTime earliesttime = RunWhen, procedu=cRUnWhat,
schedule:=True
End Sub


Sub Macro2()
My code
End Sub


--

HTH

RP
(remove nothere from the email address if mailing direct)


"Henry" wrote in message
...
I am using On Time routine from Chip Pearsons site as Follows:

Public RunWhen As Double
Public Const cRunIntervalSeconds = 30
Public Const cRUnWhat = "Macro2"

Sub StartTimer()
RunWhen = Now + TimeSerial(0, 0, cRunIntervalSeconds)
Application.OnTime earlisttime = RunWhen, procedu=cRUnWhat,

schedule:=True
End Sub


Sub Macro2()

My code

StartTimer

End Sub


Where do I sore the code and how do I actually start the procedure/
Thanks!



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 61
Default On Time

Hi Tom
Thanks for the reply
When I open the workbook I get
Compile Error:
Ambiguous name detected: StartTimer




"Tom Ogilvy" wrote:

In the vbe with our workbook as the active project,
Insert=Module

Place it there

To start it, in the project explorer in the vbe, select the ThisWorkbook
entry. In the dropdowns at the top, select workbook on the left and Open on
the right.
Private Sub Workbook_Open
StartTimer
' or if you want to run you code on opening
'Macro2
End Sub

--
Regards,
Tom Ogilvy

"Henry" wrote in message
...
I am using On Time routine from Chip Pearsons site as Follows:

Public RunWhen As Double
Public Const cRunIntervalSeconds = 30
Public Const cRUnWhat = "Macro2"

Sub StartTimer()
RunWhen = Now + TimeSerial(0, 0, cRunIntervalSeconds)
Application.OnTime earlisttime = RunWhen, procedu=cRUnWhat,

schedule:=True
End Sub


Sub Macro2()

My code

StartTimer

End Sub


Where do I sore the code and how do I actually start the procedure/
Thanks!




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default On Time

Do you have two procedures named StartTimer? That is the usual cause of this
error. Also, you should not name a module the same as a procedure, although
would be more unlikely to be the case.
--
Regards,
Tom Ogilvy

"Henry" wrote in message
...
Hi Tom
Thanks for the reply
When I open the workbook I get
Compile Error:
Ambiguous name detected: StartTimer




"Tom Ogilvy" wrote:

In the vbe with our workbook as the active project,
Insert=Module

Place it there

To start it, in the project explorer in the vbe, select the ThisWorkbook
entry. In the dropdowns at the top, select workbook on the left and

Open on
the right.
Private Sub Workbook_Open
StartTimer
' or if you want to run you code on opening
'Macro2
End Sub

--
Regards,
Tom Ogilvy

"Henry" wrote in message
...
I am using On Time routine from Chip Pearsons site as Follows:

Public RunWhen As Double
Public Const cRunIntervalSeconds = 30
Public Const cRUnWhat = "Macro2"

Sub StartTimer()
RunWhen = Now + TimeSerial(0, 0, cRunIntervalSeconds)
Application.OnTime earlisttime = RunWhen, procedu=cRUnWhat,

schedule:=True
End Sub


Sub Macro2()

My code

StartTimer

End Sub


Where do I sore the code and how do I actually start the procedure/
Thanks!








  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 61
Default On Time

OK I did find a duplicate StartTimer()
I have deleted all code except module1:

Public RunWhen As Double
Public Const cRunIntervalSeconds = 30
Public Const cRUnWhat = "Macro2"

Sub StartTimer()
RunWhen = Now + TimeSerial(0, 0, cRunIntervalSeconds)
Application.OnTime earlisttime = RunWhen, procedu=cRUnWhat, schedule:=True
End Sub


Sub Macro2()
'
'
Application.DisplayAlerts = False
applications.ScreenUpdating = False

Workbooks.OpenText Filename:="C:\Mypath\myfile.txt", _
Origin:=437, StartRow:=1, DataType:=xlDelimited, TextQualifier:= _
xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True,
Semicolon:=False, _
Comma:=True, Space:=False, Other:=False, FieldInfo:=Array(Array(1,
1), _
Array(2, 1)), TrailingMinusNumbers:=True
ActiveWorkbook.SaveAs Filename:= _
"C:\Mypath\myfile.xls", FileFormat:=xlNormal, _
Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, _
CreateBackup:=False
ActiveWorkbook.Close
Application.DisplayAlerts = True
Applications.ScreenUpdating = True

StartTimer

End Sub

and on ThisWorkbook

Private Sub Workbook_Open()
StartTimer
Macro2
End Sub

Macro2 runs on open but the 30 second update is not working

Thanks




"Tom Ogilvy" wrote:

Do you have two procedures named StartTimer? That is the usual cause of this
error. Also, you should not name a module the same as a procedure, although
would be more unlikely to be the case.
--
Regards,
Tom Ogilvy

"Henry" wrote in message
...
Hi Tom
Thanks for the reply
When I open the workbook I get
Compile Error:
Ambiguous name detected: StartTimer




"Tom Ogilvy" wrote:

In the vbe with our workbook as the active project,
Insert=Module

Place it there

To start it, in the project explorer in the vbe, select the ThisWorkbook
entry. In the dropdowns at the top, select workbook on the left and

Open on
the right.
Private Sub Workbook_Open
StartTimer
' or if you want to run you code on opening
'Macro2
End Sub

--
Regards,
Tom Ogilvy

"Henry" wrote in message
...
I am using On Time routine from Chip Pearsons site as Follows:

Public RunWhen As Double
Public Const cRunIntervalSeconds = 30
Public Const cRUnWhat = "Macro2"

Sub StartTimer()
RunWhen = Now + TimeSerial(0, 0, cRunIntervalSeconds)
Application.OnTime earlisttime = RunWhen, procedu=cRUnWhat,
schedule:=True
End Sub


Sub Macro2()

My code

StartTimer

End Sub


Where do I sore the code and how do I actually start the procedure/
Thanks!






  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default On Time

Well, by calling macro2, which calls starttimer and calling starttimer
directly, you should have two runs scheduled rather than none at all.

What I was suggesting was to call one or the other, not both:

Private Sub Workbook_Open()
Macro2
End Sub

Macro2 executes a starttimer, so it should continue the chain.

--
Regards,
Tom Ogilvy

"Henry" wrote in message
...
OK I did find a duplicate StartTimer()
I have deleted all code except module1:

Public RunWhen As Double
Public Const cRunIntervalSeconds = 30
Public Const cRUnWhat = "Macro2"

Sub StartTimer()
RunWhen = Now + TimeSerial(0, 0, cRunIntervalSeconds)
Application.OnTime earlisttime = RunWhen, procedu=cRUnWhat,

schedule:=True
End Sub


Sub Macro2()
'
'
Application.DisplayAlerts = False
applications.ScreenUpdating = False

Workbooks.OpenText Filename:="C:\Mypath\myfile.txt", _
Origin:=437, StartRow:=1, DataType:=xlDelimited, TextQualifier:= _
xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True,
Semicolon:=False, _
Comma:=True, Space:=False, Other:=False, FieldInfo:=Array(Array(1,
1), _
Array(2, 1)), TrailingMinusNumbers:=True
ActiveWorkbook.SaveAs Filename:= _
"C:\Mypath\myfile.xls", FileFormat:=xlNormal, _
Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, _
CreateBackup:=False
ActiveWorkbook.Close
Application.DisplayAlerts = True
Applications.ScreenUpdating = True

StartTimer

End Sub

and on ThisWorkbook

Private Sub Workbook_Open()
StartTimer
Macro2
End Sub

Macro2 runs on open but the 30 second update is not working

Thanks




"Tom Ogilvy" wrote:

Do you have two procedures named StartTimer? That is the usual cause of

this
error. Also, you should not name a module the same as a procedure,

although
would be more unlikely to be the case.
--
Regards,
Tom Ogilvy

"Henry" wrote in message
...
Hi Tom
Thanks for the reply
When I open the workbook I get
Compile Error:
Ambiguous name detected: StartTimer




"Tom Ogilvy" wrote:

In the vbe with our workbook as the active project,
Insert=Module

Place it there

To start it, in the project explorer in the vbe, select the

ThisWorkbook
entry. In the dropdowns at the top, select workbook on the left and

Open on
the right.
Private Sub Workbook_Open
StartTimer
' or if you want to run you code on opening
'Macro2
End Sub

--
Regards,
Tom Ogilvy

"Henry" wrote in message
...
I am using On Time routine from Chip Pearsons site as Follows:

Public RunWhen As Double
Public Const cRunIntervalSeconds = 30
Public Const cRUnWhat = "Macro2"

Sub StartTimer()
RunWhen = Now + TimeSerial(0, 0, cRunIntervalSeconds)
Application.OnTime earlisttime = RunWhen, procedu=cRUnWhat,
schedule:=True
End Sub


Sub Macro2()

My code

StartTimer

End Sub


Where do I sore the code and how do I actually start the

procedure/
Thanks!








  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 61
Default On Time

Latest Recap if I understand correctly...

In this workbook
Private Sub Workbook_Open()
StartTimer
End Sub

Module1

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

Sub StartTimer()
RunWhen = Now + TimeSerial(0, 0, cRunIntervalSeconds)
Application.OnTime earlisttime = RunWhen, procedu=cRunWhat, schedule:=True
End Sub


Sub Macro2()
Workbooks.OpenText Filename:="C:\Mypath\myfile.txt", _
Origin:=437, StartRow:=1, DataType:=xlDelimited, TextQualifier:= _
xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True,
Semicolon:=False, _
Comma:=True, Space:=False, Other:=False, FieldInfo:=Array(Array(1,
1), _
Array(2, 1)), TrailingMinusNumbers:=True
ActiveWorkbook.SaveAs Filename:= _
"C:\mypath\myfile.xls", FileFormat:=xlNormal, _
Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, _
CreateBackup:=False
ActiveWorkbook.Close

End Sub


And it still doesnt run.
Im sorry Im just not getting it. I aprreciate all of your help.

"Tom Ogilvy" wrote:

Well, by calling macro2, which calls starttimer and calling starttimer
directly, you should have two runs scheduled rather than none at all.

What I was suggesting was to call one or the other, not both:

Private Sub Workbook_Open()
Macro2
End Sub

Macro2 executes a starttimer, so it should continue the chain.

--
Regards,
Tom Ogilvy

"Henry" wrote in message
...
OK I did find a duplicate StartTimer()
I have deleted all code except module1:

Public RunWhen As Double
Public Const cRunIntervalSeconds = 30
Public Const cRUnWhat = "Macro2"

Sub StartTimer()
RunWhen = Now + TimeSerial(0, 0, cRunIntervalSeconds)
Application.OnTime earlisttime = RunWhen, procedu=cRUnWhat,

schedule:=True
End Sub


Sub Macro2()
'
'
Application.DisplayAlerts = False
applications.ScreenUpdating = False

Workbooks.OpenText Filename:="C:\Mypath\myfile.txt", _
Origin:=437, StartRow:=1, DataType:=xlDelimited, TextQualifier:= _
xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True,
Semicolon:=False, _
Comma:=True, Space:=False, Other:=False, FieldInfo:=Array(Array(1,
1), _
Array(2, 1)), TrailingMinusNumbers:=True
ActiveWorkbook.SaveAs Filename:= _
"C:\Mypath\myfile.xls", FileFormat:=xlNormal, _
Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, _
CreateBackup:=False
ActiveWorkbook.Close
Application.DisplayAlerts = True
Applications.ScreenUpdating = True

StartTimer

End Sub

and on ThisWorkbook

Private Sub Workbook_Open()
StartTimer
Macro2
End Sub

Macro2 runs on open but the 30 second update is not working

Thanks




"Tom Ogilvy" wrote:

Do you have two procedures named StartTimer? That is the usual cause of

this
error. Also, you should not name a module the same as a procedure,

although
would be more unlikely to be the case.
--
Regards,
Tom Ogilvy

"Henry" wrote in message
...
Hi Tom
Thanks for the reply
When I open the workbook I get
Compile Error:
Ambiguous name detected: StartTimer




"Tom Ogilvy" wrote:

In the vbe with our workbook as the active project,
Insert=Module

Place it there

To start it, in the project explorer in the vbe, select the

ThisWorkbook
entry. In the dropdowns at the top, select workbook on the left and
Open on
the right.
Private Sub Workbook_Open
StartTimer
' or if you want to run you code on opening
'Macro2
End Sub

--
Regards,
Tom Ogilvy

"Henry" wrote in message
...
I am using On Time routine from Chip Pearsons site as Follows:

Public RunWhen As Double
Public Const cRunIntervalSeconds = 30
Public Const cRUnWhat = "Macro2"

Sub StartTimer()
RunWhen = Now + TimeSerial(0, 0, cRunIntervalSeconds)
Application.OnTime earlisttime = RunWhen, procedu=cRUnWhat,
schedule:=True
End Sub


Sub Macro2()

My code

StartTimer

End Sub


Where do I sore the code and how do I actually start the

procedure/
Thanks!









  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default On Time

You had some typos in your commands. This worked for me:

In module1
Public RunWhen As Double
Public Const cRunIntervalSeconds = 30
Public Const cRunWhat = "Macro2"

Sub StartTimer()
RunWhen = Now + TimeSerial(0, 0, cRunIntervalSeconds)
Application.OnTime earliesttime:=RunWhen, procedu=cRunWhat,
schedule:=True
End Sub


Sub Stop_Timer()
Application.OnTime earliesttime:=RunWhen, procedu=cRunWhat,
schedule:=False

End Sub


Sub Macro2()
On Error Resume Next
Kill "C:\Mypath\myfile.xls"
On Error GoTo 0
Workbooks.OpenText Filename:="C:\Mypath\myfile.txt", _
Origin:=437, StartRow:=1, DataType:=xlDelimited, TextQualifier:= _
xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=False, _
Comma:=True, Space:=False, Other:=False, FieldInfo:=Array(Array(1, 1), _
Array(2, 1)), TrailingMinusNumbers:=True
ActiveWorkbook.SaveAs Filename:= _
"C:\mypath\myfile.xls", FileFormat:=xlNormal, _
Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, _
CreateBackup:=False
ActiveWorkbook.Close SaveChanges:=False
' added line to schedule the next run
StartTimer
End Sub
--------------------
In the Thisworkbook Module

Private Sub Workbook_Open()
StartTimer
End Sub

--
Regards,
Tom Ogilvy



--------
"Henry" wrote in message
...
Latest Recap if I understand correctly...

In this workbook
Private Sub Workbook_Open()
StartTimer
End Sub

Module1

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

Sub StartTimer()
RunWhen = Now + TimeSerial(0, 0, cRunIntervalSeconds)
Application.OnTime earlisttime = RunWhen, procedu=cRunWhat,

schedule:=True
End Sub


Sub Macro2()
Workbooks.OpenText Filename:="C:\Mypath\myfile.txt", _
Origin:=437, StartRow:=1, DataType:=xlDelimited, TextQualifier:= _
xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True,
Semicolon:=False, _
Comma:=True, Space:=False, Other:=False, FieldInfo:=Array(Array(1,
1), _
Array(2, 1)), TrailingMinusNumbers:=True
ActiveWorkbook.SaveAs Filename:= _
"C:\mypath\myfile.xls", FileFormat:=xlNormal, _
Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, _
CreateBackup:=False
ActiveWorkbook.Close

End Sub


And it still doesnt run.
Im sorry Im just not getting it. I aprreciate all of your help.

"Tom Ogilvy" wrote:

Well, by calling macro2, which calls starttimer and calling starttimer
directly, you should have two runs scheduled rather than none at all.

What I was suggesting was to call one or the other, not both:

Private Sub Workbook_Open()
Macro2
End Sub

Macro2 executes a starttimer, so it should continue the chain.

--
Regards,
Tom Ogilvy

"Henry" wrote in message
...
OK I did find a duplicate StartTimer()
I have deleted all code except module1:

Public RunWhen As Double
Public Const cRunIntervalSeconds = 30
Public Const cRUnWhat = "Macro2"

Sub StartTimer()
RunWhen = Now + TimeSerial(0, 0, cRunIntervalSeconds)
Application.OnTime earlisttime = RunWhen, procedu=cRUnWhat,

schedule:=True
End Sub


Sub Macro2()
'
'
Application.DisplayAlerts = False
applications.ScreenUpdating = False

Workbooks.OpenText Filename:="C:\Mypath\myfile.txt", _
Origin:=437, StartRow:=1, DataType:=xlDelimited,

TextQualifier:= _
xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True,
Semicolon:=False, _
Comma:=True, Space:=False, Other:=False,

FieldInfo:=Array(Array(1,
1), _
Array(2, 1)), TrailingMinusNumbers:=True
ActiveWorkbook.SaveAs Filename:= _
"C:\Mypath\myfile.xls", FileFormat:=xlNormal, _
Password:="", WriteResPassword:="",

ReadOnlyRecommended:=False, _
CreateBackup:=False
ActiveWorkbook.Close
Application.DisplayAlerts = True
Applications.ScreenUpdating = True

StartTimer

End Sub

and on ThisWorkbook

Private Sub Workbook_Open()
StartTimer
Macro2
End Sub

Macro2 runs on open but the 30 second update is not working

Thanks




"Tom Ogilvy" wrote:

Do you have two procedures named StartTimer? That is the usual cause

of
this
error. Also, you should not name a module the same as a procedure,

although
would be more unlikely to be the case.
--
Regards,
Tom Ogilvy

"Henry" wrote in message
...
Hi Tom
Thanks for the reply
When I open the workbook I get
Compile Error:
Ambiguous name detected: StartTimer




"Tom Ogilvy" wrote:

In the vbe with our workbook as the active project,
Insert=Module

Place it there

To start it, in the project explorer in the vbe, select the

ThisWorkbook
entry. In the dropdowns at the top, select workbook on the left

and
Open on
the right.
Private Sub Workbook_Open
StartTimer
' or if you want to run you code on opening
'Macro2
End Sub

--
Regards,
Tom Ogilvy

"Henry" wrote in message
...
I am using On Time routine from Chip Pearsons site as Follows:

Public RunWhen As Double
Public Const cRunIntervalSeconds = 30
Public Const cRUnWhat = "Macro2"

Sub StartTimer()
RunWhen = Now + TimeSerial(0, 0, cRunIntervalSeconds)
Application.OnTime earlisttime = RunWhen, procedu=cRUnWhat,
schedule:=True
End Sub


Sub Macro2()

My code

StartTimer

End Sub


Where do I sore the code and how do I actually start the

procedure/
Thanks!











Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Time calculations for Scheduled Time vs. Actual Time Worked The Caterer Excel Discussion (Misc queries) 1 November 29th 09 08:08 AM
straight time, time and a half, and double time Jeremy Excel Discussion (Misc queries) 3 September 23rd 08 09:03 PM
Calculate Ending time using Start Time and Elapsed Time Chief 711 Excel Worksheet Functions 5 May 13th 08 04:34 PM
verify use of TIME Function, Find Quantity Level compare to time-d nastech Excel Discussion (Misc queries) 9 July 11th 07 01:58 PM
Calculating days & time left from start date/time to end date/time marie Excel Worksheet Functions 7 December 7th 05 02:36 PM


All times are GMT +1. The time now is 09:02 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"