Need references to DAO and Scripting Runtime
Public Function GetFileNameAndDate()
On Error GoTo Err_GetFileNameAndDate
Dim objFSO As New FileSystemObject
Dim objFolder As Folder
Dim objFile As File
Dim rs As DAO.Recordset
Dim strFilePathName As String, strSrcFileDir As String
Dim strLocalTable As String, strMsg As String
'local table we want to populate with values from Excel files
strLocalTable = "FileNameAndDate"
'file directory folder we want to retrieve file names from
strSrcFileDir = "c:\temp"
'open local table for writing
Set rs = CurrentDb.OpenRecordset(strLocalTable)
'access the specified folder object
Set objFolder = objFSO.GetFolder(strSrcFileDir)
'notify user to be patient
strMsg = "There are " & objFolder.Files.Count & " files in the selected folder."
strMsg = strMsg & vbCrLf & "Processing may take some time. Please be patient."
MsgBox strMsg, , "Notice"
'iterate through files in the directory and count Excel files
For Each objFile In objFolder.Files
rs.AddNew
'write file name and date created to local table record
rs!FileName = objFile.name
rs!FileCreateDate = objFile.DateCreated
rs.Update
'move to next file in folder
Next
Exit_GetFileNameAndDate:
'clear object variables
Set objFile = Nothing
Set objFolder = Nothing
Set objFSO = Nothing
Set rs = Nothing
Exit Function
Err_GetFileNameAndDate:
MsgBox Err.Number & ", " & Err.Description, , "Error"
Resume Exit_GetFileNameAndDate
End Function
OM Gang