locked
convert todays date to text using VBA RRS feed

  • Question

  • I would like to convert todays date into text or a whole number representing the date.  Example: 10/11/0 into 10-11-10 or 101110.  The purpose of this is to save a workbook as todays date with one click ("name101110.xlsm").  I have code that works to save but needs the user to provide the date.  Is there a way to convert the date to a usable format for file saving?

    thanks in advance

    Monday, October 11, 2010 2:42 PM

Answers

  • In VBA you can create a string variable in this format using:

    Dim sDate As String

    sDate = Format(Now(), "ddmmyy")

    Hope that helps.

    • Marked as answer by Bessie Zhao Monday, October 18, 2010 9:33 AM
    Monday, October 11, 2010 3:20 PM

All replies

  • In VBA you can create a string variable in this format using:

    Dim sDate As String

    sDate = Format(Now(), "ddmmyy")

    Hope that helps.

    • Marked as answer by Bessie Zhao Monday, October 18, 2010 9:33 AM
    Monday, October 11, 2010 3:20 PM
  • Thanks but it does not help  That returns 10/11/2010 12:33:33 PM, I need 101110.
    Monday, October 11, 2010 5:36 PM
  • No my apology's IT DOES WORK.  I forgot the quotes.  Thank you very much!!
    Monday, October 11, 2010 5:38 PM