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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I get the creation date of a file(anyfile) using excel 2

Status
Not open for further replies.

eyalisr

Programmer
Apr 7, 2002
10
GB
Hi,
can anyone tell me how to get the "creation date" of a file (of any type- not just the active excel document) that exists somewhere in the Hard disk using excel vba?

thanks,
Eyal
 
If you have the Scripting Runtime on your system (and you most likely have) the following will return certain file properties, including the creation date. Be aware that this is the date that that actual file was created and not the creation date of an original. So that for example in an XL spreadsheet the value may not agree with the date return under File Properties as the creation date , which is the date the workbook was initially created. This would happen if a File SaveAs was used to create an new file.
Code:
Sub FileProperties()
Dim OFso As Object
Dim oFile As Object
Dim strFile
Set OFso = CreateObject("Scripting.FileSystemObject")
Set oFile = OFso.GetFile(&quot;Path&FileName&quot;) ' <- enter full path & name of the file
With oFile
    strFile = .Name & vbCrLf _
    & &quot;Type : &quot; & vbTab & .Type & vbCrLf _
    & &quot;Created : &quot; & vbTab & .DateCreated & vbCrLf _
    & &quot;Modified : &quot; & vbTab & .DateLastModified & vbCrLf _
    & &quot;Accessed : &quot; & vbTab & .DateLastAccessed
End With
MsgBox strFile
End Sub
If you just want the Create date, replace the With oFile loop with :

strCreated = oFile.DateCreated

A.C.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top