This video features the code you could use to move workbooks to another folder, but only if the workbook was created before a specified date. In our scenario, workbooks created before Jan 2019 are archived, any other workbooks remain in the original folder.

 

VIDEO TRAINING - LEARN AT YOUR OWN PACE

DEEP DIVE INTO LOOKUP FUNCTIONS - XLOOKUP, VLOOKUP, HLOOKUP, LOOKUP, MATCH, INDEX, IFERROR, ISNA, IFNA, LEFT, RIGHT, MID, FIND, SEARCH, LEN, SUBSTITUTE, REPLACE, TRIM, CLEAN & INDIRECTClick here to enrol

THE MS ACCESS FOR BEGINNERS' COURSE - Click here to enrol


FREE STUFF
70+ MUST KNOW EXCEL SHORTCUT KEYS: Download the pdf
UNDERSTAND & FIX EXCEL ERRORS: Download the pdf 

 

 

Here’s the code featured in the video

Sub ArchiveFiles()

Dim fso As Scripting.FileSystemObject
Set fso = New Scripting.FileSystemObject

Dim srcfol As Scripting.Folder
Set srcfol = fso.GetFolder("C:\Users\Blue Pecan\Desktop\Statements\")

Dim destfol As Scripting.Folder
Set destfol = fso.GetFolder("C:\Users\Blue Pecan\Desktop\Archive\")

Dim fle As Scripting.File

Dim flecreated As Date

For Each fle In srcfol.Files
    flecreated = fle.DateCreated

    If flecreated < "01/01/2019" Then _
    fso.MoveFile fle.Path, destfol.Path & "\" & fle.Name
Next fle

End Sub

 

Posted by Chester Tugwell