XLA routines: EE_DateFileName

Nick's picture
EE_DateFileName if a function that creates a date / time stamped file name in yyyymmdd format so that it can be sorted in Explorer
Function EE_DateFileName(strFileName As String, Optional varFileDate As Variant, Optional blnAddTime As Boolean) As String
'- takes a file name
' FileDate As Variant
' AddTime As Boolean
'- if date is missing, it appends today's date formatted as: '_yyyymmdd'
'- if AddTime is true, add 'hhmmss' of Now()
'- returns file name with appended date stamping
    Dim strNewFileName As String
'http://excelexperts.com/xla-routines-eeDateFileName    for updates on this function

    strNewFileName = strFileName
    If IsMissing(varFileDate) Or IsEmpty(varFileDate) Then
        strNewFileName = strNewFileName & "_" & Format(Date, "yyyymmdd")
        strNewFileName = strNewFileName & "_" & Format(CDate(varFileDate), "yyyymmdd")
    End If
    If blnAddTime Then
        strNewFileName = strNewFileName & "_" & Format(Now(), "hhmmss")
    End If
    EE_DateFileName = strNewFileName
End Function