PDA

View Full Version : Variable Filename in Macro to SaveAs



AZIQN
02-25-2009, 12:32 PM
Hi, I am trying to include a way to automatically save a file after the macro is run, but I do not want to hardcode a filename into the macro. Each day the macro is run, I need a unique filename specified for that day (including the date). I've been thinking that a user input stored in a var from a msgbox might work, but I'm not sure how to correctly code that in the macro.

The file name I would like to have is: "Deposit 2-25-09.xls"

Can a msgbox value (2-25-09) stored in varDate be placed into the file name? Such as:

ActiveWorkbook.SaveAs Filename:= "C:\...\Deposit "varDate".xls"...

Thanks for your help!

Bob Phillips
02-25-2009, 12:53 PM
ActiveWorkbook.SaveAs Filename:= "C:\...\Deposit " & varDate & ".xls"


If varDate is a date variable use



ActiveWorkbook.SaveAs Filename:= "C:\...\Deposit " & Format(varDate, "m-d-yy") & ".xls"

Kenneth Hobs
02-25-2009, 12:54 PM
Welcome to the forum!

ActiveWorkbook.SaveAs Filename:= "C:\Deposit " & Format(Date, "m-dd-yy") & ".xls".

AZIQN
02-25-2009, 01:04 PM
Thank you xld and Kenneth!