Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default LastModified Date of Excel file

Hi all,

The function FileDateTime returns "the date and time when a file was created
or last modified." But it doesn't seem to work (the way I thought it would)
when the file is an open XLS workbook.

I would like to put in a cell, the date of my excel file was last modified
and last saved to disk. I thought that this would do it:

Sub TestDate()
fileSpec = ThisWorkbook.FullName
Dim myDate As String
myDate = FileDateTime(fileSpec)
Range("A1").Value = myDate
End Sub

But this gets the date and time the file was opened. How do I get the date
when the file was saved to disk (like the "Last Modified" date in Windows
Explorer)?

I've also tried
Dim fso, f
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFile(fileSpec)
Range("A2").Value = fileSpec + " " + Str(f.DateLastModified)
Range("A3").Value = fileSpec + " " + Str(f.DateLastAccessed)
Range("A4").Value = fileSpec + " " + Str(f.DateCreated)
but DateLastModified and DateLastAccessed are always the same - the date the
file was opened.

Thanks in advance,


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 79
Default LastModified Date of Excel file

An example

Sub ShowInProcessActive()
Dim fs, f, f1, fc, s, sf
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder("P:\Data\ipopen\")
Set sf = f.subfolders
For Each f1 In sf
If Left(f1.datelastmodified, Len(Date)) = Str(Date) Then
s = s & f1.Name & vbTab & f1.datelastmodified
s = s & vbCrLf & vbCrLf
End If
Next
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder("I:\Projects\arms\in process\")
Set sf = f.files
For Each f1 In sf
If Left(f1.datelastmodified, Len(Date)) = Str(Date - 1) Then
s = s & f1.Name & vbTab & f1.datelastmodified
s = s & vbCrLf & vbCrLf
End If
Next
MsgBox s, , "In-Process folders modified today"
End Sub


HTH, Greg
"R Douglas" wrote in message
...
Hi all,

The function FileDateTime returns "the date and time when a file was

created
or last modified." But it doesn't seem to work (the way I thought it

would)
when the file is an open XLS workbook.

I would like to put in a cell, the date of my excel file was last modified
and last saved to disk. I thought that this would do it:

Sub TestDate()
fileSpec = ThisWorkbook.FullName
Dim myDate As String
myDate = FileDateTime(fileSpec)
Range("A1").Value = myDate
End Sub

But this gets the date and time the file was opened. How do I get the

date
when the file was saved to disk (like the "Last Modified" date in Windows
Explorer)?

I've also tried
Dim fso, f
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFile(fileSpec)
Range("A2").Value = fileSpec + " " + Str(f.DateLastModified)
Range("A3").Value = fileSpec + " " + Str(f.DateLastAccessed)
Range("A4").Value = fileSpec + " " + Str(f.DateCreated)
but DateLastModified and DateLastAccessed are always the same - the date t

he
file was opened.

Thanks in advance,




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default LastModified Date of Excel file

Thanks Greg,

Datelastmodified doesn't seem to work with its own excel file. It does not
give the date and time the file was last modified. It gives the current
time:

Sub TestDate()
fileSpec = ThisWorkbook.FullName
Set fs = CreateObject("Scripting.FileSystemObject")
Set f1 = fs.GetFile(fileSpec)
MsgBox (f1.datelastmodified) '<<GIVES CURRENT DATE & TIME, NOT LAST
MODIFIED DATE
End Sub

Maybe there is no way to get the last modified time of an open excel file.

Roger

"Greg Koppel" wrote in message
...
An example

Sub ShowInProcessActive()
Dim fs, f, f1, fc, s, sf
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder("P:\Data\ipopen\")
Set sf = f.subfolders
For Each f1 In sf
If Left(f1.datelastmodified, Len(Date)) = Str(Date) Then
s = s & f1.Name & vbTab & f1.datelastmodified
s = s & vbCrLf & vbCrLf
End If
Next
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder("I:\Projects\arms\in process\")
Set sf = f.files
For Each f1 In sf
If Left(f1.datelastmodified, Len(Date)) = Str(Date - 1) Then
s = s & f1.Name & vbTab & f1.datelastmodified
s = s & vbCrLf & vbCrLf
End If
Next
MsgBox s, , "In-Process folders modified today"
End Sub


HTH, Greg
"R Douglas" wrote in message
...
Hi all,

The function FileDateTime returns "the date and time when a file was

created
or last modified." But it doesn't seem to work (the way I thought it

would)
when the file is an open XLS workbook.

I would like to put in a cell, the date of my excel file was last

modified
and last saved to disk. I thought that this would do it:

Sub TestDate()
fileSpec = ThisWorkbook.FullName
Dim myDate As String
myDate = FileDateTime(fileSpec)
Range("A1").Value = myDate
End Sub

But this gets the date and time the file was opened. How do I get the

date
when the file was saved to disk (like the "Last Modified" date in

Windows
Explorer)?

I've also tried
Dim fso, f
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFile(fileSpec)
Range("A2").Value = fileSpec + " " + Str(f.DateLastModified)
Range("A3").Value = fileSpec + " " + Str(f.DateLastAccessed)
Range("A4").Value = fileSpec + " " + Str(f.DateCreated)
but DateLastModified and DateLastAccessed are always the same - the date

t
he
file was opened.

Thanks in advance,






Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
change date in excel from today to original date of file Nelson Excel Discussion (Misc queries) 1 September 18th 09 08:33 AM
how to expire Excel file after certain date Som Excel Discussion (Misc queries) 15 March 14th 09 03:58 PM
Retrieve the date of another excel file BRABUS[_2_] Excel Discussion (Misc queries) 2 May 10th 07 03:14 PM
How to link an Excel file due date to Outlook calendar date? anok New Users to Excel 0 May 9th 07 09:31 PM
Saving an excel file using a date Ed Davis Excel Worksheet Functions 5 April 7th 07 05:44 PM


All times are GMT +1. The time now is 10:18 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"