Please Help: Return Date Modified for File in Directory

Mitch3

New Member
Joined
Apr 2, 2013
Messages
3
Hi,
I am unsuccessfully trying to use a function to return the date modified with the below Sub AKAname. Perhaps I should rename some variable names, but I'm not really sure if that is right, or how to streamline the Function LastModified with the Sub AKAname (listed below). Any help is much much appreciated!

Sub AKAname()
Range("A65536").End(xlUp).Select
Selection.Offset(1, 0).Select
Dim FSO As Object
Dim strName As String
Dim strArr(1 To 1048576, 1 To 1) As String, i As Long
CurrentRow = ActiveCell.Row


' Enter the folder name here
Const strDir As String = "Q:\AKAname\in\" ' drive you're searching


Let strName = Dir$(strDir & "**") 'insert file type if you'd like
Do While strName <> vbNullString
Let i = i + 1
Let strArr(i, 1) = strDir & strName
Let strName = Dir$()
Loop
Set FSO = CreateObject("Scripting.FileSystemObject")
'currently voided out: Call recurseSubFolders(fso.GetFolder(strDir), strArr(), i)
Set FSO = Nothing
'good place to stop...code that was here begins with: If i > 0 Then
If i > 0 Then
'Range("A1").Resize(i).Value = strArr
Range("A65536").End(xlUp).Select
Selection.Offset(1, 0).Select
End If
End Sub

Function LastModified(ByRef Folder As Object, _
ByRef strArr() As String, _
ByRef i As Long) '(Optional Filename As String) '(strArr As String) '(Filename As String)
Dim FSO As Object
Dim oFile As Object
'Dim Filename As String

If Len(Folder(strArr)) = 0 Then
'If Len(strArr)) = 0 Then
'If Len(Dir(strArr)) = 0 Then
'If Len(Dir(Filename)) = 0 Then

LastModified = CVErr(xlErrValue)

Else

Set FSO = CreateObject("Scripting.FileSystemObject")
Set oFile = FSO.getfile(strArr)
'Set oFile = FSO.getfile(Filename)
LastModified = oFile.DateLastModified

End If

Set oFile = Nothing
Set FSO = Nothing

End Function
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.

Forum statistics

Threads
1,215,064
Messages
6,122,936
Members
449,094
Latest member
teemeren

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top