How to do a "Save As" in vba code, saving my current Excel workbook with datestamp?

Analytic Lunatic picture Analytic Lunatic · Jun 18, 2013 · Viewed 425.1k times · Source

I have an Excel Workbook that on form button click I want to save a copy of the workbook with the filename being the current date.

I keep trying the the following ActiveWorkbook.SaveAs ("\\filePath\FormFlow To MSExcel\" & Left(Now(), 10)) but am receiving Run-time error '1004': Method 'SaveAs' of object'_Workbook' failed.

Can anyone assist me with this? I'm still very new to developing for Excel.

Answer

chancea picture chancea · Jun 18, 2013

Most likely the path you are trying to access does not exist. It seems you are trying to save to a relative location and you do not have an file extension in that string. If you need to use relative paths you can parse the path from ActiveWorkbook.FullName

EDIT: Better syntax would also be

ActiveWorkbook.SaveAs Filename:=myFileName, FileFormat:=xlWorkbookNormal