如何进行“另存为"在 vba 代码中,使用日期戳保存我当前的 Excel 工作簿? [英] How to do a "Save As" in vba code, saving my current Excel workbook with datestamp?
问题描述
我有一个 Excel 工作簿,在表单按钮上单击我想保存工作簿的副本,文件名是当前日期.
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.
我一直在尝试以下ActiveWorkbook.SaveAs ("\\filePath\FormFlow To MSExcel\" & Left(Now(), 10))
但我收到 运行时错误 '1004':方法 'SaveAs'对象_Workbook"失败.
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.
谁能帮我解决这个问题?我对 Excel 开发还很陌生.
Can anyone assist me with this? I'm still very new to developing for Excel.
推荐答案
很可能您尝试访问的路径不存在.您似乎正在尝试保存到相对位置,并且该字符串中没有文件扩展名.如果您需要使用相对路径,您可以从 ActiveWorkbook.FullName
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
更好的语法也是
ActiveWorkbook.SaveAs Filename:=myFileName, FileFormat:=xlWorkbookNormal
这篇关于如何进行“另存为"在 vba 代码中,使用日期戳保存我当前的 Excel 工作簿?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!