Click here to Skip to main content
15,880,392 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hello,
I have a macro I wrote which refreshes 13 separate files. The total time of refresh is 6 hours which locks my excel during this time. Ideally, I'd like to schedule the macro to run after hours when my pc is off in order to have free up my excel during business hours.
Any assistance would be greatly appreciated.
Thank you,
Posted
Updated 11-Oct-18 3:16am
Comments
Ron Beyer 20-Jan-14 18:13pm    
How do you expect the macro to run if your PC is off? If your BIOS supports a wake timer you can use that to wake your PC up, but other than that I don't think this will work.
Sergey Alexandrovich Kryukov 20-Jan-14 18:17pm    
This is a hardware problem. Your task is to write code when a computer is off. :-)
—SA
Ron Beyer 20-Jan-14 19:57pm    
Could you imagine the power savings in the world if we could get tasks to run when the computer is powered down? I'll start on the patent...
Sergey Alexandrovich Kryukov 21-Jan-14 0:35am    
Ah, great point! Of course. This will be even better then even that well-known power over IP.
—SA
PIEBALDconsult 20-Jan-14 18:35pm    
Run it on a different computer?

The definition of 'off' is that your computer is not running. So, I assume this is a joke.

If you mean 'when I am logged off', then write a service to do it.
 
Share this answer
 
Comments
Member 10530881 21-Jan-14 8:31am    
Yes, I am looking for a code to start a macro I wrote while the computer is in sleep or hibernating for example. The total refresh time is 6+ hours and I am trying to find a way to do this outside of work hours in lieu of waking up at 2 a.m. to start the macro. I am new to writing codes and macros; therefore any assistance would be greatly appreciated.
Member 10530881 21-Jan-14 9:52am    
Below is my code and at the specified time, nothing is happening.

Sub openFile()

Application.OnTime TimeValue("9:50:00"), "refreshAll"

Workbooks.Open Filename:= _
"C:\Users\v-giwhal\Documents\Bulk Update Reports\FY14 CR CAM Qualified Opportunity Report"

Application.Run "'FY14 CR CAM Qualified Opportunity Report.xlsb'!refreshAll"
ActiveWorkbook.Save
ActiveWindow.Close

End Sub
Christian Graus 21-Jan-14 13:42pm    
Did you read my answer ? Write a service. A scheduled task can also be used, actually, that may be simpler.
Member 10530881 21-Jan-14 14:28pm    
Hi Christian,
I do not know how to write a service. Below is my code. If I run the code, it works; however if I leave it with the OnTime statement, it does not run once the time approaches.

Sub openFile()

Application.OnTime TimeValue("13:00:00"), "refreshFile()"

End Sub

Sub refreshFile()

Workbooks.Open Filename:= _
"C:\Users\v-giwhal\Documents\Bulk Update Reports\FY14 CR CAM Qualified Opportunity Report"
Application.Run "'FY14 CR CAM Qualified Opportunity Report.xlsb'!refreshAll"
ActiveWorkbook.Save
ActiveWindow.Close

End Sub
Christian Graus 21-Jan-14 14:30pm    
OK, well, you have two options.

1 - read one of the many articles on how to write a service
2 - set up your script as a scheduled task

2 is easier and will probably work.
Create a new workbook with a macro that runs once the workbook is opened:

Private Sub Workbook_Open()
'insert your code here'
End Sub

use "Task Scheduler" and create a task that opens that workbook at the desired time.
- under the "conditions" tab of the task, there will be a check box "Wake the computer to run this task". Make sure that is checked.

Do this and I believe the code should work as long as the PC is sleeping and not fully powered down. Please let me know if this works or not.
Thanks! :)

-Kyle
 
Share this answer
 
Comments
Patrice T 11-Oct-18 9:29am    
Almost 5 years too late.
lets guess a solution was found before.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900