Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 389
Default LastSavedDate

I have a list of file names with their full name (ie Path + Name) in column
A. 50 files total. Is there a macro or funtion that I can return the last
saved date for each file in column B and the time it was saved in column C?

Thank you for your help.

Steven



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default LastSavedDate

demo's from the immediate window:

dt = Filedatetime("C:\data\KZ081-Default Survey1.xls")
? cdate(clng(dt))
3/18/02
? dt-clng(dt)
6:08:40 AM

--
Regards,
Tom Ogilvy


"Steven" wrote in message
...
I have a list of file names with their full name (ie Path + Name) in

column
A. 50 files total. Is there a macro or funtion that I can return the

last
saved date for each file in column B and the time it was saved in column

C?

Thank you for your help.

Steven





  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default LastSavedDate

One way:

Option Explicit
Sub testme()

Dim iRow As Long
Dim FirstRow As Long
Dim LastRow As Long
Dim wks As Worksheet
Dim testStr As String
Dim myFileName As String
Dim myDate As Date

Set wks = Worksheets("sheet1")

With wks
FirstRow = 2 'headers in row 1???
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row

For iRow = FirstRow To LastRow
myFileName = .Cells(iRow, "A").Value
testStr = ""
On Error Resume Next
testStr = Dir(myFileName)
On Error GoTo 0

If testStr = "" Then
.Cells(iRow, "B").Value = "Not Found"
.Cells(iRow, "C").ClearContents
Else
myDate = FileDateTime(myFileName)
With .Cells(iRow, "B")
.NumberFormat = "mm/dd/yyyy"
.Value = Int(myDate)
End With

With .Cells(iRow, "C")
.NumberFormat = "hh:mm:ss"
.Value = myDate - Int(myDate)
End With

End If
Next iRow
End With

End Sub

Although, I think I'd keep the time and date in one cell. And just format it
pretty.

Steven wrote:

I have a list of file names with their full name (ie Path + Name) in column
A. 50 files total. Is there a macro or funtion that I can return the last
saved date for each file in column B and the time it was saved in column C?

Thank you for your help.

Steven


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 389
Default LastSavedDate

Dave:

Thank you for your help. That is a really nice macro. I was looking
through the Macro VB Help for how to get LastSavedBy but could not find
anything. Is there a way to get who saved the file last?

Thanks,

Steven

"Dave Peterson" wrote:

One way:

Option Explicit
Sub testme()

Dim iRow As Long
Dim FirstRow As Long
Dim LastRow As Long
Dim wks As Worksheet
Dim testStr As String
Dim myFileName As String
Dim myDate As Date

Set wks = Worksheets("sheet1")

With wks
FirstRow = 2 'headers in row 1???
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row

For iRow = FirstRow To LastRow
myFileName = .Cells(iRow, "A").Value
testStr = ""
On Error Resume Next
testStr = Dir(myFileName)
On Error GoTo 0

If testStr = "" Then
.Cells(iRow, "B").Value = "Not Found"
.Cells(iRow, "C").ClearContents
Else
myDate = FileDateTime(myFileName)
With .Cells(iRow, "B")
.NumberFormat = "mm/dd/yyyy"
.Value = Int(myDate)
End With

With .Cells(iRow, "C")
.NumberFormat = "hh:mm:ss"
.Value = myDate - Int(myDate)
End With

End If
Next iRow
End With

End Sub

Although, I think I'd keep the time and date in one cell. And just format it
pretty.

Steven wrote:

I have a list of file names with their full name (ie Path + Name) in column
A. 50 files total. Is there a macro or funtion that I can return the last
saved date for each file in column B and the time it was saved in column C?

Thank you for your help.

Steven


--

Dave Peterson

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default LastSavedDate

? dt-clng(dt)
6:08:40 AM

should be

? dt-int(dt)
6:08:40 AM

--
Regards,
Tom Ogilvy

"Tom Ogilvy" wrote in message
...
demo's from the immediate window:

dt = Filedatetime("C:\data\KZ081-Default Survey1.xls")
? cdate(clng(dt))
3/18/02
? dt-clng(dt)
6:08:40 AM

--
Regards,
Tom Ogilvy


"Steven" wrote in message
...
I have a list of file names with their full name (ie Path + Name) in

column
A. 50 files total. Is there a macro or funtion that I can return the

last
saved date for each file in column B and the time it was saved in column

C?

Thank you for your help.

Steven









  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default LastSavedDate

Are these Excel files (or MSOffice files)?

If yes, you can use the technique at Chip Pearson's site:
http://cpearson.com/excel/docprop.htm

Look for "Document Properties Of Closed Files"

and be careful. There's instructions for both version 1.2 and 2.0 of that DSO
dll.

Steven wrote:

Dave:

Thank you for your help. That is a really nice macro. I was looking
through the Macro VB Help for how to get LastSavedBy but could not find
anything. Is there a way to get who saved the file last?

Thanks,

Steven

"Dave Peterson" wrote:

One way:

Option Explicit
Sub testme()

Dim iRow As Long
Dim FirstRow As Long
Dim LastRow As Long
Dim wks As Worksheet
Dim testStr As String
Dim myFileName As String
Dim myDate As Date

Set wks = Worksheets("sheet1")

With wks
FirstRow = 2 'headers in row 1???
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row

For iRow = FirstRow To LastRow
myFileName = .Cells(iRow, "A").Value
testStr = ""
On Error Resume Next
testStr = Dir(myFileName)
On Error GoTo 0

If testStr = "" Then
.Cells(iRow, "B").Value = "Not Found"
.Cells(iRow, "C").ClearContents
Else
myDate = FileDateTime(myFileName)
With .Cells(iRow, "B")
.NumberFormat = "mm/dd/yyyy"
.Value = Int(myDate)
End With

With .Cells(iRow, "C")
.NumberFormat = "hh:mm:ss"
.Value = myDate - Int(myDate)
End With

End If
Next iRow
End With

End Sub

Although, I think I'd keep the time and date in one cell. And just format it
pretty.

Steven wrote:

I have a list of file names with their full name (ie Path + Name) in column
A. 50 files total. Is there a macro or funtion that I can return the last
saved date for each file in column B and the time it was saved in column C?

Thank you for your help.

Steven


--

Dave Peterson


--

Dave Peterson
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



All times are GMT +1. The time now is 07:08 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"