Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Use VBA to retrieve a file's date? 1

Status
Not open for further replies.

dmon000

Technical User
Sep 9, 2003
79
US
How would one retrieve a file's date using VBA? For example, if the file name was N:\download\flatfile.txt

Thanks!!
 
A starting point:
MsgBox FileDateTime("N:\download\flatfile.txt")

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Here's another way. No harm in seeing more then one way. The following loops through a directory, but you can modify it to just do one file.
I created a listbox on a form, setting Row Source Type to Value List.
I then created a command button with the following code on OnClick event:

Private Sub Command2_Click()
Dim strFill As String
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace("C:\excelforcourse")
For Each strFileName In objFolder.Items
strFill = strFill & strFileName & " " & objFolder.GetDetailsOf(strFileName, 3) & ";"
Next
ListProps.RowSource = strFill
End Sub

strFill statement is on one line.
You'll notice the 3 in the GetDetailsOF - that the Date Modified index. There's 34 properties of a file you can retrieve this way.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top