Results 1 to 23 of 23

Auto delete files after 30 days

Threaded View

  1. #1
    Forum Contributor
    Join Date
    11-07-2013
    Location
    Singapore
    MS-Off Ver
    Excel 2007
    Posts
    100

    Auto delete files after 30 days

    Dear All Excel Expert,

    Need your advise on this. Currently my VBA works in such a way that when the files in a folder is there for 30days, it will delete away automatically. So that we don't have to delete the temp files manually.

    However, for below code, the path is set in VBA scripting. This make it not so userfriendly as can't share with others to use this function too since they don't have programming knowledge. As such, anyone has any idea how can I allow user to key in their prefer path in Excel so that everytime they just run the Excel using startup, VBA will look in Excel worksheet on the the path they choose for their prefer folders and remove 30 days old files?

    I have a few worksheet in the StartUp Excel file.. And this worksheet name save is "Deletefiles" so user just key in their prefer path under this work sheet and it will do the auto delete for them.

    Thank you all.

    
    Dir_Path = "D:\Documents\Temp"
        iMaxAge = 30 ' Set the number of days
         
        Set oFSO = CreateObject("Scripting.FileSystemObject")
        If oFSO.FolderExists(Dir_Path) Then 'Check that the folder exists
            For Each oFile In oFSO.GetFolder(Dir_Path).Files
                If DateDiff("d", oFile.DateLastModified, Now) > iMaxAge Then 'Look at each file to check if it is older than 30 days
                    oFile.Delete
                    MsgBox "Temp File Deleted!"
                End If
            Next
        End If
    
    End Sub
    Last edited by EvelynLoh; 09-07-2017 at 02:59 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Need help to auto merge different files and delete sub total rows after merging
    By ec4excel in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-15-2015, 12:12 PM
  2. [SOLVED] Extracting from table based on criteria and auto delete rows after 4 days from database
    By ACALEX in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-18-2014, 10:33 AM
  3. Replies: 2
    Last Post: 07-31-2013, 02:00 PM
  4. Write text files, run another program, delete txt files upon alt-tab / exit..
    By niels007 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-05-2011, 10:05 AM
  5. Delete all files in directory, msgbox list files before delete.
    By randell.graybill in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-01-2010, 09:28 PM
  6. Application.GetOpenFilename, Attach files to Email, Move files, Delete Original.
    By D_Rennie in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-08-2009, 12:11 AM
  7. Limit macro conversion to only .txt files or delete existing .xls files
    By macro_noob in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-06-2008, 03:54 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1