Home > front end >  save excel file including YYMMYY HHMM
save excel file including YYMMYY HHMM

Time:01-11

unable to follow below syntax

FileName = Format(Date, "yymmdd.hhmm") & " TRI" & ".xlsx"

result is "230111 0000 TRI" what i need is if 9am result to be "230111.0900 TRI"

CodePudding user response:

will be DateTime.Now()

FileName = Format(DateTime.Now(), "yymmdd hhmm") & " TRI" & ".xlsx"

CodePudding user response:

FileName = Format(TestDate, "yymmdd.HHmm") & " TRI.xlsx"

Sub Test()
    Const ExpectedResult As String = "230111.0900 TRI.xlsx"
    Const TestDate As Date = #1/11/2023 9:00:00 AM#

    Dim FileName As String
    FileName = Format(TestDate, "yymmdd.HHmm") & " TRI.xlsx"
    Debug.Print FileName, "Test: "; IIf(FileName = ExpectedResult, "PASS", "FAIL")

End Sub

Immediate Window Result

Note: Format() is something that we use a lot as programmers. It would be advantageous to read the docs: Format function

  • Related