Results 1 to 7 of 7

Thread: Capture the "Last Modifed" date from FilePicker

  1. #1
    Junior Member
    Join Date
    Oct 2014
    Posts
    26
    Rep Power
    0

    Capture the "Last Modifed" date from FilePicker

    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.


    Code:
    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/watch?v=SIDLFRkUEIo&lc=UgzTF5vvB67Zbfs9qvx4AaABAg
    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=UgzMCQUIQgrbec400jl4AaABAg
    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=vXyMScSbhk4&lc=Ugxa2VYHMWJWXA6QI294AaABAg. 9irLgSdeU3r9itU7zdnWHw
    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=Ugw6UrV69zpeKvLOeOV4AaABAg. 9ht16tzryC49htJ6TpIOXR
    https://www.youtube.com/watch?v=LuAipOW8BNQ&lc=UgwMKwGZpDjv7vi7pCx4AaABAg
    https://www.youtube.com/watch?v=LuAipOW8BNQ&lc=Ugw6UrV69zpeKvLOeOV4AaABAg. 9ht16tzryC49htOKs4jh3M
    https://www.youtube.com/watch?v=LuAipOW8BNQ&lc=UgxVW-am20rQ5GFuJ9F4AaABAg
    https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA
    Last edited by DocAElstein; 10-26-2023 at 12:21 PM.

  2. #2
    Senior Member alansidman's Avatar
    Join Date
    Apr 2012
    Posts
    125
    Rep Power
    13
    How about this:

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

  3. #3
    Senior Member
    Join Date
    Jun 2012
    Posts
    337
    Rep Power
    12
    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'

  4. #4
    Junior Member
    Join Date
    Oct 2014
    Posts
    26
    Rep Power
    0
    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?

  5. #5
    Administrator Admin's Avatar
    Join Date
    Mar 2011
    Posts
    1,122
    Rep Power
    10
    Code:
    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
    Cheers !

    Excel Range to BBCode Table
    Use Social Networking Tools If You Like the Answers !

    Message to Cross Posters

    @ Home - Office 2010/2013/2016 on Win 10 (64 bit); @ Work - Office 2016 on Win 10 (64 bit)

  6. #6
    Senior Member
    Join Date
    Jun 2012
    Posts
    337
    Rep Power
    12
    Code:
    Sub M_snb()
       With Application.FileDialog(3)
          .InitialFileName = "G:\OF\*.xls"
          .Show
          Cells(1) = FileDateTime(.SelectedItems(1))
        End With
    End Sub

  7. #7
    Junior Member
    Join Date
    Oct 2014
    Posts
    26
    Rep Power
    0
    Thanks Admin and snb for your feedback. I appreciate you help

    here's the snippet of my code:

    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)
    Last edited by jeremiah_j2k; 09-09-2015 at 03:55 PM.

Similar Threads

  1. VBA Versions of my "Get Field" and "Get Reverse Field" formulas
    By Rick Rothstein in forum Rick Rothstein's Corner
    Replies: 4
    Last Post: 06-02-2017, 06:15 PM
  2. Replies: 1
    Last Post: 02-10-2015, 09:41 AM
  3. Replies: 4
    Last Post: 09-09-2013, 05:13 PM
  4. Displayin Date/Time in "original" time zone
    By Rasm in forum Excel Help
    Replies: 4
    Last Post: 04-21-2012, 02:02 AM
  5. Ordinal Suffix (i.e., "st", "nd", "rd" and "th")
    By Rick Rothstein in forum Rick Rothstein's Corner
    Replies: 0
    Last Post: 03-20-2012, 03:46 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •