It's ok then? The original post said: 1, Every month I want to copy all files that are 1 month old (these are all .PDF files) from folder A to folder B.
So, we determine the date from (1) month ago: OldDate = DateAdd("m", -1, DateValue(Now())) and move any file older than that date. So, today (1/1/2011), no files from October would be moved, but anything from September would be moved. Have I misunderstood your requirement? Did you mean files that are EXACTLY one month old? If (DateDiff("d", OldDate, fDate) = 0) Then or files that are LESS than 1 month old? If (DateDiff("d", OldDate, fDate) > 0) Then ?? Paul ----------------------------------------- “Do all the good you can, By all the means you can, In all the ways you can, In all the places you can, At all the times you can, To all the people you can, As long as ever you can.” - John Wesley ----------------------------------------- ________________________________ From: Dave <davidstev...@gmail.com> To: MS EXCEL AND VBA MACROS <excel-macros@googlegroups.com> Sent: Tue, November 1, 2011 12:50:11 PM Subject: Re: $$Excel-Macros$$ Copy Files & then go back amd delete them Here is how I have your script with all the mods you suggested. Its still not copying the files from October 2011. Move command will not work as it screws with permissions etc. When I run the script the Window says Old Files: 10/1/2011 and then it lists all the files created in September 2011. Sub Archive_Files() Dim fso, fldr, flc, f, fName, Fil, fDate Dim OldDate Dim Folder_From, Folder_To Dim msg, msg2 '----------------------------------------------------------------------------- Folder_From = "P:\test\From\" 'Note: trailing "\" is significant! Folder_To = "P:\test\to\" '----------------------------------------------------------------------------- Set fso = CreateObject("Scripting.FileSystemObject") ' OldDate = DateAdd("m", -1, Now()) 'Determines date 1 month ago OldDate = DateAdd("m", -1, DateValue(Now())) ' msg = "Old Files: " msg = "Old Files: " & OldDate msg2 = "Recent Files:" '----------------------------------------------------------------------------- If fso.folderexists(Folder_From) Then '------------------------------------------------------ Set fldr = fso.getfolder(Folder_From) Set flc = fldr.Files For Each f In flc fName = Folder_From & "\" & f.Name Set Fil = fso.getfile(fName) fDate = Fil.datelastmodified If (DateDiff("d", OldDate, fDate) <= 1) Then msg = msg & Chr(13) & Format(DateDiff("d", OldDate, fDate), "0000") & " " & Format(fDate, "mm-dd-yyyy") & " " & f.Name fso.copyfile fName, Folder_To If (fso.fileexists(Folder_To & f.Name)) Then fso.deletefile (fName) End If Else msg2 = msg2 & Chr(13) & Format(DateDiff("d", OldDate, fDate), "0000") & " " & Format(fDate, "mm-dd-yyyy") & " " & f.Name End If Next MsgBox msg & Chr(13) & Chr(13) & msg2 End If End Sub -- FORUM RULES (925+ members already BANNED for violation) 1) Use concise, accurate thread titles. Poor thread titles, like Please Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get quick attention or may not be answered. 2) Don't post a question in the thread of another member. 3) Don't post questions regarding breaking or bypassing any security measure. 4) Acknowledge the responses you receive, good or bad. 5) Cross-promotion of, or links to, forums competitive to this forum in signatures are prohibited. NOTE : Don't ever post personal or confidential data in a workbook. Forum owners and members are not responsible for any loss. ------------------------------------------------------------------------------------------------------ To post to this group, send email to excel-macros@googlegroups.com -- FORUM RULES (925+ members already BANNED for violation) 1) Use concise, accurate thread titles. Poor thread titles, like Please Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get quick attention or may not be answered. 2) Don't post a question in the thread of another member. 3) Don't post questions regarding breaking or bypassing any security measure. 4) Acknowledge the responses you receive, good or bad. 5) Cross-promotion of, or links to, forums competitive to this forum in signatures are prohibited. NOTE : Don't ever post personal or confidential data in a workbook. Forum owners and members are not responsible for any loss. ------------------------------------------------------------------------------------------------------ To post to this group, send email to excel-macros@googlegroups.com