Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old October 27th, 2008, 11:47 AM
Registered User
 
Join Date: Oct 2008
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Schedule a VBA macro to run at a specific time

Hello,

I need to schedule my PC to run an Excel macro automatically at a specified time, for exmaple, 6 PM every day. I have no idea about how to do that. Any help would be greatly appreciated.

Peter
Reply With Quote
  #2 (permalink)  
Old October 27th, 2008, 07:25 PM
Authorized User
Points: 193, Level: 3
Points: 193, Level: 3 Points: 193, Level: 3 Points: 193, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2007
Location: North East Pennsylvania, USA.
Posts: 48
Thanks: 0
Thanked 4 Times in 4 Posts
Default

Peter,

http://www.ozgrid.com/Excel/run-macro-on-time.htm

There are many times when it would be great to have any macro run at a predetermined time or run it at specified intervals. Fortunately Excel has made this a relatively simple task, when you know how.

Application.OnTime

This Method is what we can use to achieve the automatically running of Excel Macros. Let's suppose we have a macro that we wish to Run each day at 18:00 (6:00 PM). The first problem will be how to kick-off the OnTime Method. This we can do via the Workbook Open Event. The fastest way to get to the Private Module of the Workbook Object (ThisWorkbook) is to right click on the Excel icon next to "File" and select "View Code"

Code:
Private Sub Workbook_Open()

    Application.OnTime TimeValue("18:00:00"), "MyMacro"

End Sub

Have a great day,
Stan

[/code]


stanleydgromjr

Windows Vista Business and Excel 2003, 2007.
Reply With Quote
  #3 (permalink)  
Old October 28th, 2008, 04:54 PM
Registered User
 
Join Date: Oct 2008
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Stan,

Thank you very much for your reply. But I think the problem still remains: How to schedule the procedure of "Workbook_Open" to start automatically at a predetermined time, especially when the Excel is not open.

Have a good day,
Peter
Reply With Quote
  #4 (permalink)  
Old October 29th, 2008, 02:10 AM
Friend of Wrox
Points: 3,060, Level: 23
Points: 3,060, Level: 23 Points: 3,060, Level: 23 Points: 3,060, Level: 23
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2005
Location: , , .
Posts: 812
Thanks: 1
Thanked 53 Times in 49 Posts
Default

Hi Peter

I don't think you can fire the Open event from outside. Either you need to open the Workbook for the event to be fired

or

Use Application.Run to call the Macro in the workbook

Code:
Sub RunAMacro()

Application.Run "'C:\temp\MAcWB.xls'!MyMacro"

End Sub
Cheers
Shasur

http://www.dotnetdud.blogspot.com

VBA Tips & Tricks (http://www.vbadud.blogspot.com)
Reply With Quote
  #5 (permalink)  
Old October 29th, 2008, 11:50 AM
JP JP is offline
Authorized User
Points: 199, Level: 3
Points: 199, Level: 3 Points: 199, Level: 3 Points: 199, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2008
Location: NYC, NY, USA.
Posts: 57
Thanks: 1
Thanked 3 Times in 3 Posts
Default

How about this?

http://krgreenlee.blogspot.com/2006/...dows-task.html

--JP
Reply With Quote
  #6 (permalink)  
Old October 29th, 2008, 08:09 PM
Registered User
 
Join Date: Oct 2008
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks,
Peter
Reply With Quote
  #7 (permalink)  
Old April 4th, 2013, 03:49 AM
Registered User
Points: 18, Level: 1
Points: 18, Level: 1 Points: 18, Level: 1 Points: 18, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2013
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Suggest

Hi,

I used this code to automate my macro
Private Sub Workbook_Open()

Application.OnTime TimeValue("08:58:00"), "RUN"
Application.OnTime TimeValue("09:00:00"), "RUN"
Application.OnTime TimeValue("10:00:00"), "RUN"
Application.OnTime TimeValue("11:50:00"), "RUN"
Application.OnTime TimeValue("12:00:00"), "RUN"
Application.OnTime TimeValue("13:00:00"), "RUN"
Application.OnTime TimeValue("13:10:00"), "RUN"
Application.OnTime TimeValue("14:00:00"), "RUN"
Application.OnTime TimeValue("15:00:00"), "RUN"
Application.OnTime TimeValue("15:33:00"), "RUN"
Application.OnTime TimeValue("16:00:00"), "RUN"
Application.OnTime TimeValue("16:30:00"), "RUN"
Application.OnTime TimeValue("17:00:00"), "RUN"
Application.OnTime TimeValue("17:30:00"), "RUN"
Application.OnTime TimeValue("18:00:00"), "RUN"
Application.OnTime TimeValue("19:00:00"), "RUN"
Application.OnTime TimeValue("20:00:00"), "RUN"

End Sub
Sub RunAMacro()

Application.RUN "path'!RUN"

End Sub

But the problem is...If my cursor is placed on other excel sheet at above mentioned time then macro executed in that sheet not in 'SGX Macro Annuals'.

Could any one suggest the currect code.

Thanks

Last edited by psukanya; April 4th, 2013 at 04:28 AM..
Reply With Quote
  #8 (permalink)  
Old October 26th, 2015, 01:36 AM
Registered User
Points: 3, Level: 1
Points: 3, Level: 1 Points: 3, Level: 1 Points: 3, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2015
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I tried this but it is not running can you share excel file.
Reply With Quote
  #9 (permalink)  
Old October 31st, 2015, 08:41 AM
Authorized User
Points: 192, Level: 3
Points: 192, Level: 3 Points: 192, Level: 3 Points: 192, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2015
Location: South Africa
Posts: 48
Thanks: 0
Thanked 5 Times in 5 Posts
Default

Hi,

I think you need to use Windows task scheduler to run the workbook at a specified interval.

Here is the XML of an example task.

<?xml version="1.0" encoding="UTF-16" ?>
- <Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
<RegistrationInfo />
<Triggers />
- <Principals>
- <Principal id="Author">
<UserId>MyName-PC\MyAdminName</UserId>
<LogonType>InteractiveToken</LogonType>
<RunLevel>HighestAvailable</RunLevel>
</Principal>
</Principals>
- <Settings>
<MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
<DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries>
<StopIfGoingOnBatteries>false</StopIfGoingOnBatteries>
<AllowHardTerminate>true</AllowHardTerminate>
<StartWhenAvailable>false</StartWhenAvailable>
<RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
- <IdleSettings>
<Duration>PT10M</Duration>
<WaitTimeout>PT1H</WaitTimeout>
<StopOnIdleEnd>true</StopOnIdleEnd>
<RestartOnIdle>false</RestartOnIdle>
</IdleSettings>
<AllowStartOnDemand>true</AllowStartOnDemand>
<Enabled>true</Enabled>
<Hidden>false</Hidden>
<RunOnlyIfIdle>false</RunOnlyIfIdle>
<WakeToRun>false</WakeToRun>
<ExecutionTimeLimit>PT72H</ExecutionTimeLimit>
<Priority>5</Priority>
</Settings>
- <Actions Context="Author">
- <Exec>
<Command>C:\Program Files (x86)\IObit\IObit Uninstaller\IObitUninstaler.exe</Command>
<Arguments>/UninstallExplorer</Arguments>
</Exec>
</Actions>
</Task>
__________________
Nostalgia 4 Infinity

Last edited by Zakalwe; October 31st, 2015 at 08:55 AM..
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Possible to run macro from another workbook? rmilward Excel VBA 2 September 26th, 2009 08:00 PM
Schedule a VBA macro to run at a specific time peterlihh Other Programming Languages 0 October 24th, 2008 07:15 PM
VBA Macros not showing up in the run macro menu d.lee84 Access VBA 9 August 21st, 2007 09:37 AM
run a method in a schedule vinu_p C# 2005 0 June 30th, 2006 02:29 AM
Macro Doesn't Run? CoryKutchera Excel VBA 3 January 5th, 2005 10:30 AM



All times are GMT -4. The time now is 02:38 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.