Consulting

Results 1 to 4 of 4

Thread: macro to delete files - three days later

  1. #1
    VBAX Regular
    Joined
    Dec 2007
    Posts
    45
    Location

    macro to delete files - three days later

    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

  2. #2
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    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.

  3. #3
    VBAX Regular
    Joined
    Dec 2007
    Posts
    45
    Location
    Thanks Kenneth, only thing is how do i create a BAT file?, bit knew to this!

    Thanks

  4. #4
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •