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
Bookmarks