This video demonstrates how to import the most recently created Excel workbook in a specified folder into the current workbook. The solution uses VBA’s FileSystemObject.

 

LIVE ONLINE TRAINING COURSES WITH A LIVE TUTOR - AVAILABLE WORLDWIDE

Private or public courses available:
ONLINE EXCEL TRAINING (LIVE TUTOR): See Our Training Dates - Excel Fundamentals, Intermediate, Advanced and VBA Courses. 

ONLINE MS ACCESS TRAINING (LIVE TUTOR): See Our Training Dates
ONLINE MS PROJECT TRAINING (LIVE TUTOR): See Our Training Dates
ONLINE POWERPOINT TRAINING (LIVE TUTOR): See Our Training Dates


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

DEEP DIVE INTO DATE FUNCTIONS - TODAY, DATEDIF, WORKDAY, NETWORKDAYS, EOMONTH, EDATE, DATE, DATEVALUE, DAY, MONTH, YEAR, WEEKNUM, ISOWEEKNUM, WEEKDAY & YEARFRAC.
Click 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 is the code featured in the video.

Sub ImportMostRecentFile()

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

Dim MyFolder As Scripting.Folder
Set MyFolder = fso.GetFolder("File Path for folder containing files")

Dim Fle As Scripting.File
Dim NewestFile As Scripting.File

For Each Fle In MyFolder.Files

    If NewestFile Is Nothing Then Set NewestFile = Fle
        If NewestFile.DateCreated < Fle.DateCreated Then Set NewestFile = Fle

Next Fle

Workbooks.Open NewestFile
ActiveWorkbook.Worksheets("Sheet1").Copy after:=Workbooks("Name of Current Workbook").Worksheets("Sheet1")
ActiveSheet.Name = NewestFile.Name

Workbooks(NewestFile.Name).Close


End Sub

 

Posted by Chester Tugwell