+ Reply to Thread
Results 1 to 5 of 5

How to add Time & Date details in file name using VBA

  1. #1
    Registered User
    Join Date
    06-03-2010
    Location
    Houston, Tx
    MS-Off Ver
    Excel 2003
    Posts
    3

    How to add Time & Date details in file name using VBA

    I am creating an Excel spreadsheet Master, that will eventually save the Master Sheet as a new Excel spreadsheet along with a Word report. How can I add the Time and Date fields to the Excel and Word file names from within my SaveAs VBA code run within Excel?

  2. #2
    Forum Expert Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    Office 2003, 2010, 2013, 2016, 365
    Posts
    3,284

    Re: How to add Time & Date details in file name using VBA

    Please Login or Register  to view this content.

  3. #3
    Valued Forum Contributor
    Join Date
    03-23-2008
    Location
    Tennessee
    MS-Off Ver
    Office 2007
    Posts
    706

    Re: How to add Time & Date details in file name using VBA

    You can use a version of this to save it something like "Temp 065417"

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    06-03-2010
    Location
    Houston, Tx
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: How to add Time & Date details in file name using VBA

    Hutch

    Many thanks for your reply. Would this apply to a MS Word document too e.g. ext .doc?

    Also Do I assume I will need to add the following to the start of my VBA string?
    Dim strDate As String
    Dim strTime As String
    Dim strFilename As String
    strDate = Format((Date), "MMMM d yyyy")
    strTime = Format((Time), " hhmmss")

    Sorry I am still getting back into VBA from a great deal of time off!!!!

  5. #5
    Valued Forum Contributor
    Join Date
    03-23-2008
    Location
    Tennessee
    MS-Off Ver
    Office 2007
    Posts
    706

    Re: How to add Time & Date details in file name using VBA

    Alan - There are no variables that need to be declared in the code I provided. It just adds the current time to the filename, (Now), formatted as "hhmmss".

    Sorry,but I don't know what would need to be changed to make this work on a Word file. You'll need help from someone better than me for that.

    Best of luck.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1