PDA

View Full Version : Command Button Programming In Excel



fiestaball
12-09-2005, 03:47 PM
Anyone know how to program a command button in Excel? Here is what I am trying to do. I need a command button that when clicked will save my current file and append the date to the end. e.g. 'Backup12092005'. I have tried to record a macro and then look at the code and then tried to append '=TODAY()'
but that results in the file being saved as 'Backup=TODAY()' which is not what I desire to happen.

dbax791
12-09-2005, 07:56 PM
It's because Today() is an excel function and not an Excel VBA function.

Getting dates to save in that format is a little tricky in VBA but it can be done:

Dim Filename As String

Filename = "C:\temp\test" & CStr(DatePart("m", Date)) & CStr(DatePart("d", Date)) & CStr(DatePart("yyyy", Date)) & ".xls"


ActiveWorkbook.SaveAs Filename:= _
Filename, FileFormat _
:=xlNormal, Password:="", WriteResPassword:="", ReadOnlyRecommended:= _
False, CreateBackup:=False
End Sub

eSDee
12-09-2005, 08:31 PM
you're the man dbax