PDA

View Full Version : macro to delete files - three days later



obriensj
04-23-2009, 05:51 AM
Hi,

A bit of a long shot here but is it possible to delete some excel files I have in a folder with a macro.
The catch being I need the macro to be created today and delete files that will be in the folder three days later?
The macro would have to run itself as I would not be here to run it. So sort of like a scheduled macro to run at a certain time of the week and delete files in the folder I tell it.
Is this possible at all?

Thanks

Kenneth Hobs
04-23-2009, 06:59 AM
Set a BAT file to open your xls, at a Window's Scheduled event. It's open event would do what you want and then close itself.

obriensj
04-23-2009, 08:19 AM
Thanks Kenneth, only thing is how do i create a BAT file?, bit knew to this!

Thanks

Kenneth Hobs
04-23-2009, 09:52 AM
The BAT file is just a text file so enter something like this.

@echo off
x:\ken.xls
exit

If you can do WScript, then a text VBS file might go something like:

Dim vbshell

Set vbshell = CreateObject("WScript.shell")
vbshell.Run "cmd /c x:\ken.xls", 0, false

Set vbshell = Nothing
These only work if your Window's file association is Excel for XLS files but that is the default.

Of course your ken.xls file must have the code in the Open event to do what you wanted.