Use Now rather than Date and add the timestring format string. I also added a method to create all folders, not just one, if needed.
I like to build a string and use Debug.Print to view a run result before using it fully. Remove comments and after a run View the Immediate window to see the string.
Code:
Sub filename_cellvalue()
Dim Path As String, filename As String
Dim fn As String, strDir As String
strDir = "D:\AB\TestDir\"
filename = Range("A1")
If Dir(strDir, vbDirectory) = "" Then
'MkDir strDir
Shell "cmd /c md " & """" & strDir & """", vbHide 'Drive must exist.
Else
MsgBox "Directory exists."
End If
fn = strDir & filename & "_" & Environ("username") & "_" & Format(Now, "d-m-yy hh:mm:ss") & ".xls"
'Debug.Print fn
'Exit Sub
ActiveWorkbook.SaveAs fn, 56
End Sub
Bookmarks