Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Running a macro every half hour

If I want to run a macro every half hour, do I use the
OnTime method? This is what I have tried:

Dim KeepingTime As Boolean
Dim Times As Long

Times = 10

KeepingTime = True

Do While KeepingTime = True

Application.OnTime Now + TimeValue
("00:30:0"), "GetAll"

Times = Times - 1

If Times < 1 Then
KeepingTime = False
End If
Loop

Scott
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,236
Default Running a macro every half hour

I have an example on my website


--
Rob van Gelder - http://www.vangelder.co.nz/excel


"Scott" wrote in message
...
If I want to run a macro every half hour, do I use the
OnTime method? This is what I have tried:

Dim KeepingTime As Boolean
Dim Times As Long

Times = 10

KeepingTime = True

Do While KeepingTime = True

Application.OnTime Now + TimeValue
("00:30:0"), "GetAll"

Times = Times - 1

If Times < 1 Then
KeepingTime = False
End If
Loop

Scott



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 30
Default Running a macro every half hour

Thanks for the help!!!


-----Original Message-----
I have an example on my website


--
Rob van Gelder - http://www.vangelder.co.nz/excel


"Scott" wrote in message
...
If I want to run a macro every half hour, do I use the
OnTime method? This is what I have tried:

Dim KeepingTime As Boolean
Dim Times As Long

Times = 10

KeepingTime = True

Do While KeepingTime = True

Application.OnTime Now + TimeValue
("00:30:0"), "GetAll"

Times = Times - 1

If Times < 1 Then
KeepingTime = False
End If
Loop

Scott



.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 30
Default Running a macro every half hour

Thanks for the help!!!

-----Original Message-----
I have an example on my website


--
Rob van Gelder - http://www.vangelder.co.nz/excel


"Scott" wrote in message
...
If I want to run a macro every half hour, do I use the
OnTime method? This is what I have tried:

Dim KeepingTime As Boolean
Dim Times As Long

Times = 10

KeepingTime = True

Do While KeepingTime = True

Application.OnTime Now + TimeValue
("00:30:0"), "GetAll"

Times = Times - 1

If Times < 1 Then
KeepingTime = False
End If
Loop

Scott



.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default Running a macro every half hour

Change

Dim Times As Long

to

Static Times As Long

otherwise a new local variable will be created each time the Sub is run.

One alternative:

Public Sub GetAll()
Static Times As Long
Static bAlreadyRun As Boolean
If Not bAlreadyRun Then
Times = 10
bAlreadyRun = True
End If

'do stuff here

Times = Times - 1
If Times = 1 Then _
Application.OnTime Now + TimeSerial(0, 30, 0), "GetAll"
End Sub







In article ,
"Scott" wrote:

If I want to run a macro every half hour, do I use the
OnTime method? This is what I have tried:

Dim KeepingTime As Boolean
Dim Times As Long

Times = 10

KeepingTime = True

Do While KeepingTime = True

Application.OnTime Now + TimeValue
("00:30:0"), "GetAll"

Times = Times - 1

If Times < 1 Then
KeepingTime = False
End If
Loop

Scott



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
Convert time to Half Hour inverval BenS Excel Discussion (Misc queries) 4 May 20th 23 11:44 AM
How do I round time down to the nearest half hour? KatJ Excel Worksheet Functions 4 April 3rd 23 07:32 PM
Add half hour Connie Martin Excel Discussion (Misc queries) 7 May 21st 08 05:45 PM
Convert Time To Half Hour - Pt 2 - OOPS! BenS Excel Discussion (Misc queries) 4 March 29th 07 09:52 PM
Calculate time difference to the half hour Ken Ivins Excel Worksheet Functions 6 July 17th 05 05:48 PM


All times are GMT +1. The time now is 11:03 PM.

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

About Us

"It's about Microsoft Excel"