PDA

View Full Version : VBA code is needed to Do X every 1 hour



khaledocom
05-21-2011, 09:22 PM
A very good morning to all,

-I have a workbook called updater.xls,
I need a code so updater can open another Excel file (SalesMaster.xls) every one hour, then updater to close itself at 02:00 PM every working day (Sunday to Thursday).

Note:

Daily I open updater at 08:00 AM (Sunday to Thursday).

- When Excel is closed improperly way, next time you open it it shows you a recovery pane on left side shows files were opened before.
How can I disable this?, how to disable auto recover pane/bar on Excel?

Please help.

Thanks in advance.

Aussiebear
05-21-2011, 10:01 PM
When Excel is closed improperly way, next time you open it it shows you a recovery pane on left side shows files were opened before.
How can I disable this?, how to disable auto recover pane/bar on Excel?

This function was designed by Microsoft to assist when Excel is improperly closed. Surely it is far more important to find out why Excel is not closing correctly and fix this than override the safety net ?

Is Excel being incorrectly closed by the User or is the issue being generated by a corrupted or damaged file?

khaledocom
05-21-2011, 10:52 PM
Twice a week at least the current may be cut suddenly without any notice.
Systems then have improper shutdown.

Aussiebear
05-22-2011, 12:28 PM
If you are using 2007, Open Excel Options, Save there is a option of a checkbox forAutosave and a timeframe. You could turn this off, but I wouldn't recommend this.

khaledocom
05-22-2011, 08:40 PM
Thanks bros but how about the first one: to do every one hour code?

pjotter
05-23-2011, 12:57 AM
You could probably use application.ontime and for it to stop after 2 in the afternoon(why you want to quit it in the afternoon is beyond me...), you just have to check the time with TimeValue(Now())

Use the application.ontime in combination with TimeValue(Now()).
You could use application.wait, but I think that disables some excel functions, and I'm guessing you don't want that.

For the next example, call HourlyUpdate inside the Workbook_open event and it will run every hour from the time you open it till 2 PM. The workbook will close itself afterwards.

Sub HourlyUpdate()

<The code for updating and calling other workbook>

If TimeValue(Now()) < "14:00:00" And TimeValue(Now()) > "7:01:00" Then
application.ontime Now + TimeValue("01:00:00"), "HourlyUpdate"
else
Thisworkbook.close
End if
End sub


Could change it up a bit to fit your needs, but it should work like this.