File date time stamp

J

Joe

I am trying to retrieve the timedate stamp for a file
called file.007 which is stored in my documents the
following code successfully finds the file but not the
date stamp any one out their able to help.

Dim varItem As Variant
Dim Imod As Variant
Dim mLfiles As Variant
With Application.FileSearch
.NewSearch
.LookIn = "C:\Documents and Settings\Joe\My
Documents"
.FileName = "FILE.007"
.LastModified
.Execute
For Each varItem In .FoundFiles
Debug.Print varItem
Imod = Application.FileSearch.LastModified
Debug.Print FileDateTime(Imod)
Next varItem
Regards
Joe
 
R

Ron Weiner

Joe

Try this function to get the date time stamp of the unambigious filename
passed in strFilespec.

Function FileDateTime(strFilespec as String) As Date
Dim fso As Object, f As Object
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFile(filespec)
FileDateTime = f.DateCreated
Set f = Nothing
Set fso = Nothing
End Function

From the immediate you can type
? FileDateTime("C:\Documents and Settings\Joe\My Documents\File.007")

Ron W
 
R

Ron Weiner

Paste the function into your code module and call it like.

If you want the result in a variable called yourvariable

yourvariable = FileDateTime("C:\Documents and Settings\Joe\My
Documents\File.007")

Then you can use it like any other variable in your app.

Ron W
 
J

Joe

Sorry Ron, the str appears to be missing from the line

Set f = fso.GetFile(Filespec)

In the sample code and I could not see the missing code,
how I got it to work in the immediate window I don't know.
But with the missing "str" it works brilliantly.

Many thanks for your support
Joe
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top