PDA

View Full Version : Capture the "Last Modifed" date from FilePicker



jeremiah_j2k
09-01-2015, 01:28 PM
Hello All,

Has anyone tried to capture the last date modified of the file selected from FilePicker? I'm trying to figure out how to insert the its value to a cell but getting an error using the below code. Please help and thanks in advanced for assistance.



Sub Generate_Report()
Application.ScreenUpdating = False

With Application.FileDialog(msoFileDialogFilePicker)
.AllowMultiSelect = False
.ButtonName = "Open"
.Filters.clear
.Filters.Add "Excel Files", "*.csv"
.Filters.Add "CSV File", "*.csv"
.title = "Open Raw Data"
.Show
If .SelectedItems.count Then
strFileSelected = .SelectedItems(1)
Else
'MsgBox "Cancelled by user!"
Exit Sub 'Ideally, should exit from the bottom of the sub-routine.
End If
End With

Range("C7").Value = Format(strFileSelected.BuiltinDocumentProperties("Creation Date"), "short date")
Range("E7").Value = Format(strFileSelected.BuiltinDocumentProperties("Last Save Time"), "short date")





https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA (https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA)
https://www.youtube.com/watch?v=SIDLFRkUEIo&lc=UgzTF5vvB67Zbfs9qvx4AaABAg (https://www.youtube.com/watch?v=SIDLFRkUEIo&lc=UgzTF5vvB67Zbfs9qvx4AaABAg)
https://www.youtube.com/watch?v=v_1iqtOnUMg&lc=UgxLtKj969oiIu7zNb94AaABAg (https://www.youtube.com/watch?v=v_1iqtOnUMg&lc=UgxLtKj969oiIu7zNb94AaABAg)
https://www.youtube.com/watch?v=f7xZivqLZxc&lc=Ugxq4JHRza_zx3sz0fx4AaABAg (https://www.youtube.com/watch?v=f7xZivqLZxc&lc=Ugxq4JHRza_zx3sz0fx4AaABAg)
https://www.youtube.com/watch?v=f7xZivqLZxc&lc=Ugxq4JHRza_zx3sz0fx4AaABAg (https://www.youtube.com/watch?v=f7xZivqLZxc&lc=Ugxq4JHRza_zx3sz0fx4AaABAg)
https://www.youtube.com/watch?v=f7xZivqLZxc&lc=UgzMCQUIQgrbec400jl4AaABAg (https://www.youtube.com/watch?v=f7xZivqLZxc&lc=UgzMCQUIQgrbec400jl4AaABAg)
https://www.youtube.com/watch?v=LuAipOW8BNQ&lc=Ugz0Uy2bCSCTb1W-0_14AaABAg (https://www.youtube.com/watch?v=LuAipOW8BNQ&lc=Ugz0Uy2bCSCTb1W-0_14AaABAg)
https://www.youtube.com/watch?v=ITI1HaFeq_g&lc=Ugx12mI-a39T41NaZ8F4AaABAg.9iDQqIP56NV9iFD0AkeeJG (https://www.youtube.com/watch?v=ITI1HaFeq_g&lc=Ugx12mI-a39T41NaZ8F4AaABAg.9iDQqIP56NV9iFD0AkeeJG)
https://www.youtube.com/watch?v=vXyMScSbhk4&lc=Ugxa2VYHMWJWXA6QI294AaABAg.9irLgSdeU3r9itU7zdnW Hw (https://www.youtube.com/watch?v=vXyMScSbhk4&lc=Ugxa2VYHMWJWXA6QI294AaABAg.9irLgSdeU3r9itU7zdnW Hw)
https://www.youtube.com/watch?v=tPRv-ATUBe4&lc=UgzFkoI0n_BxwnwVMcZ4AaABAg (https://www.youtube.com/watch?v=tPRv-ATUBe4&lc=UgzFkoI0n_BxwnwVMcZ4AaABAg)
https://www.youtube.com/watch?v=LuAipOW8BNQ&lc=Ugz0Uy2bCSCTb1W-0_14AaABAg.9htChVuaX9W9htG01cKBzX (https://www.youtube.com/watch?v=LuAipOW8BNQ&lc=Ugz0Uy2bCSCTb1W-0_14AaABAg.9htChVuaX9W9htG01cKBzX)
https://www.youtube.com/watch?v=LuAipOW8BNQ&lc=Ugw6UrV69zpeKvLOeOV4AaABAg.9ht16tzryC49htJ6TpIO XR (https://www.youtube.com/watch?v=LuAipOW8BNQ&lc=Ugw6UrV69zpeKvLOeOV4AaABAg.9ht16tzryC49htJ6TpIO XR)
https://www.youtube.com/watch?v=LuAipOW8BNQ&lc=UgwMKwGZpDjv7vi7pCx4AaABAg (https://www.youtube.com/watch?v=LuAipOW8BNQ&lc=UgwMKwGZpDjv7vi7pCx4AaABAg)
https://www.youtube.com/watch?v=LuAipOW8BNQ&lc=Ugw6UrV69zpeKvLOeOV4AaABAg.9ht16tzryC49htOKs4jh 3M (https://www.youtube.com/watch?v=LuAipOW8BNQ&lc=Ugw6UrV69zpeKvLOeOV4AaABAg.9ht16tzryC49htOKs4jh 3M)
https://www.youtube.com/watch?v=LuAipOW8BNQ&lc=UgxVW-am20rQ5GFuJ9F4AaABAg (https://www.youtube.com/watch?v=LuAipOW8BNQ&lc=UgxVW-am20rQ5GFuJ9F4AaABAg)
https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA (https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA)

alansidman
09-01-2015, 06:21 PM
How about this:


Sub LastSaved()
Range("A1") = ThisWorkbook.BuiltinDocumentProperties("Last Save Time")
End Sub
Change the range appropriately

snb
09-01-2015, 06:25 PM
With Application.FileDialog(msoFileDialogFilePicker)
.AllowMultiSelect = False

If you can only select 1 file it's always the last modified & the first modified.

Your question is a 'contradictio in terrminis'

jeremiah_j2k
09-02-2015, 10:29 AM
Thanks for your feedback.. :) is it possible to capture the "Last Save Time" of the file selected from the FilePicker and put its value in a cell?

Admin
09-04-2015, 03:48 PM
Sub Generate_Report()

Dim strFileSelected As String

With Application.FileDialog(msoFileDialogFilePicker)
.AllowMultiSelect = False
.ButtonName = "Open"
.Filters.Clear
.Filters.Add "Excel Files", "*.xls*"
.Filters.Add "CSV File", "*.csv"
.Title = "Open Raw Data"
.Show
If .SelectedItems.Count Then
strFileSelected = .SelectedItems(1)
Else
'MsgBox "Cancelled by user!"
Exit Sub 'Ideally, should exit from the bottom of the sub-routine.
End If

MsgBox VBA.FileDateTime(strFileSelected)

End With

End Sub

snb
09-04-2015, 04:55 PM
Sub M_snb()
With Application.FileDialog(3)
.InitialFileName = "G:\OF\*.xls"
.Show
Cells(1) = FileDateTime(.SelectedItems(1))
End With
End Sub

jeremiah_j2k
09-09-2015, 03:41 PM
Thanks Admin and snb for your feedback. I appreciate you help :)

here's the snippet of my code:


Dim strFileSelected As String

Application.ScreenUpdating = False

With Application.FileDialog(msoFileDialogFilePicker)
.AllowMultiSelect = False
.ButtonName = "Open"
.Filters.clear
.Filters.Add "Excel Files", "*.csv"
.Filters.Add "CSV File", "*.csv"
.title = "Open Raw Data"
.Show
If .SelectedItems.count Then
strFileSelected = .SelectedItems(1)
Else
'MsgBox "Cancelled by user!"
Exit Sub 'Ideally, should exit from the bottom of the sub-routine.
End If
End With


Range("C7").Value = VBA.FileDateTime(strFileSelected)