How to create Automatic Filenames in Excel

T

Trevor6410

I am trying to work out how to get Excel to automatically create the File
Name when the Workbook is saved. I want a filename to be create using the
contents of a given Cell + the current date/time... Ideally, I want a Macro
attached to the sheet which Saves the document.
 
D

Dave Peterson

Option Explicit
Sub testme03()

Dim myFileName As String

myFileName = ThisWorkbook.Worksheets("Sheet99").Range("a99").Value _
& "--" & Format(Now, "yyyy_mm_dd__hh_mm_ss") & ".xls"

ThisWorkbook.SaveAs Filename:=myFileName
End Sub

Not much testing--no folder included (unless it's in that cell).
 
Top