Consulting

Results 1 to 11 of 11

Thread: Insert The Created Time And Last Modified Time In Cells In Excel With VBA Code

  1. #1
    VBAX Regular
    Joined
    Apr 2018
    Posts
    50
    Location

    Insert The Created Time And Last Modified Time In Cells In Excel With VBA Code

    I have a win.7/MS Office 2010

    I'm trying to get a file creation date on a footer on my sheet but i dont want it on my sheet.

    I tried using the example off this site : https://www.extendoffice.com/documen...fied-time.html
    I'm not allowed to download that site on my computer. (dont want to get in trouble)

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,729
    Location
    To be clear, you want the file Creation Date, not the Last Modified Date ... correct?



    Option Explicit
    
    Sub InsertCreationDate()
        Dim D As Date
        
        D = CreateObject("Scripting.FileSystemObject").GetFile(ThisWorkbook.FullName).DateCreated
        
        MsgBox D
    
        'the Date, etc. can get formatted: font bold point, etc
        ActiveSheet.PageSetup.LeftFooter = "&""Arial,Bold""&12 " & Format(D, "yyyy-mm-dd hh:mm")
    
    End Sub
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  3. #3
    VBAX Regular
    Joined
    Apr 2018
    Posts
    50
    Location
    You are correct, just the creation date. Do I have to fill in or replace anything in the vba area or does it automatically show up

  4. #4
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,729
    Location
    Quote Originally Posted by Ladyj205 View Post
    You are correct, just the creation date. Do I have to fill in or replace anything in the vba area or does it automatically show up
    All depends on what you want

    The macro just shows the creation date being added to the left footer for the active sheet with a manually run macro

    You could add the code to the Before_Print event and you could also have the creation date added to any or all worksheets

    You could add text or formatting to this left footer or to the center and right footers



    Edit --

    Another way - I just had the first FSO code handy, but I should have thought of this first

    Sub InsertCreationDate_2()
    
        ActiveSheet.PageSetup.LeftFooter = "&""Arial,Bold""&12 " & Format(ThisWorkbook.BuiltinDocumentProperties("Creation Date"), "yyyy-mm-dd hh:mm")
    
    End Sub
    Last edited by Paul_Hossler; 06-26-2018 at 08:21 PM.
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  5. #5
    VBAX Regular
    Joined
    Apr 2018
    Posts
    50
    Location
    how about if i want creation date from a previous workbook?

  6. #6
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,729
    Location
    Quote Originally Posted by Ladyj205 View Post
    how about if i want creation date from a previous workbook?

    Then I'd use the FSO approach from #2 with the workbook of interest

     CreateObject("Scripting.FileSystemObject").GetFile("C:\Users\Me\Documents\MyWorkbook.xlsx").DateCreated
    
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  7. #7
    VBAX Regular
    Joined
    Apr 2018
    Posts
    50
    Location
    i got a error message. when i try to do it from my T:

  8. #8
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,729
    Location
    There's lots of error messages - which one?

    I don't understand what a T: is

    What is your whole macro?

    These work for me


    Option Explicit
    
    
    'this adds the creation date for THIS workbook to the left footer on the active sheet in THIS workbook
    Sub InsertCreationDate_2()
        ActiveSheet.PageSetup.LeftFooter = "&""Arial,Bold""&12 " & Format(ThisWorkbook.BuiltinDocumentProperties("Creation Date"), "yyyy-mm-dd hh:mm")
    End Sub
    
    
    
    'this adds the creation date for a SAVED workbook to the left footer on the active sheet in THIS workbook
    Sub InsertCreationDate()
        Dim D As Date
        
        D = CreateObject("Scripting.FileSystemObject").GetFile("C:\Users\Daddy\Projects\Chemistry\ChemHelper_20.xlsm").DateCreated
    
        'the Date, etc. can get formatted: font bold point, etc
        ActiveSheet.PageSetup.LeftFooter = "&""Arial,Bold""&12 " & Format(D, "yyyy-mm-dd hh:mm")
    End Sub
    Attached Files Attached Files
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  9. #9
    VBAX Regular
    Joined
    Apr 2018
    Posts
    50
    Location
    Run-time error '53': file not found....i had pressed f5

  10. #10
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,729
    Location
    If you put your own file name in it should not be not found
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  11. #11
    VBAX Regular
    Joined
    Apr 2018
    Posts
    50
    Location
    T: is a drive i have on my computer thats all. sorry for the confusion.

Posting Permissions

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