VBS Script To Retrieve A Specified Directories Files And Last Accessed Date And Send To Excel

 

This VBS script will allow you to enter a Directory Folder name and will list all of the files in the directory folder along with their last accessed date timestamp.

 

VBS Script:

 

strDirectoryFolder = InputBox ("Enter Directory Folder Name")

 

Set objExcel = CreateObject("Excel.Application")

objExcel.Visible = True

objExcel.Workbooks.Add

intRow = 2

 

objExcel.Cells(1, 1).Value = "File Name"

objExcel.Cells(1, 2).Value = "Last Accessed"

 

Set Fso = CreateObject("Scripting.FileSystemObject")

Set objDirectory = Fso.GetFolder(strDirectoryFolder)

For Each objFile in objDirectory.Files

objExcel.Cells(intRow, 1).Value = objFile.Name

objExcel.Cells(intRow, 2).Value = objFile.DateLastAccessed

intRow = intRow + 1

Next

 

objExcel.Range("A1:B1").Select

objExcel.Selection.Interior.ColorIndex = 19

objExcel.Selection.Font.ColorIndex = 11

objExcel.Selection.Font.Bold = True

objExcel.Cells.EntireColumn.AutoFit

 

Set objSheet = objExcel.ActiveWorkbook.Worksheets(1)

Set objRange = objExcel.Range("A2")

objRange.Sort objRange,1,,,,,,1

 

MsgBox "Done"

 

 

 

 

Published Saturday, March 22, 2008 6:20 PM by dhite
Filed under:

Comments

No Comments