+ Reply to Thread
Results 1 to 7 of 7

correct statement to return time

Hybrid View

  1. #1
    Valued Forum Contributor
    Join Date
    11-16-2004
    Location
    Devon UK
    MS-Off Ver
    2010
    Posts
    357

    correct statement to return time

    I have the following code
    d = ThisWorkbook.path & "\Current Version " & "_" & Sheets("data").Cells(1, 209).Value & "_" & Day(Date) & "_" & Month(Date) & "_" & Year(Date) & ".xls"
    which contains the workbook name, and date, the code opens a new workbook and saves it under this name. I would like to add the time to this so that if i later run the program again it will have a different filename (different time)
    Can anyone help with the correct statement to return the time?
    Last edited by tryer; 11-29-2008 at 01:34 PM.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492
    Does this do what you want:

    d = ThisWorkbook.path & "\Current Version " & "_" & Sheets("data").Cells(1, 209).Value & "_" & Format(dDate,"mm-dd-yyyy_hhnn) & ".xls"
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Valued Forum Contributor
    Join Date
    11-16-2004
    Location
    Devon UK
    MS-Off Ver
    2010
    Posts
    357
    Thank for the reply. nfortunately I get a compile error message saying expected seperator or ) with the . prior to xls highlighted, I cant see any missing brackets

  4. #4
    Forum Expert
    Join Date
    12-23-2006
    Location
    germany
    MS-Off Ver
    XL2003 / 2007 / 2010
    Posts
    6,326
    Could it be there is a " missing?

    Format(dDate,"mm-dd-yyyy_hhnn")

  5. #5
    Valued Forum Contributor
    Join Date
    11-16-2004
    Location
    Devon UK
    MS-Off Ver
    2010
    Posts
    357
    Thanks Arthur your right there was a " missing. this code now works but I think I must be missing something it currently returns the day/date as 12-30-1899_0000.xls so presumably I have to pick up the system date and time from somewhere?

  6. #6
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678
    If you'd like the the files to sort in date order,
    Format(Now(), "yyyy-MMdd-hhmm")
    Entia non sunt multiplicanda sine necessitate

  7. #7
    Valued Forum Contributor
    Join Date
    11-16-2004
    Location
    Devon UK
    MS-Off Ver
    2010
    Posts
    357
    Thanks Shg, that did it

+ 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