简体   繁体   English

另存为VBA Excel

[英]SaveAs VBA Excel

I am trying to auto-save a document with a specific file name followed by yesterdays date using the Now() function. 我正在尝试使用Now()函数自动保存具有特定文件名的文档,然后保存昨天的日期。

Every time I run the code I am hit with "Compile error: Expected: list separator or )" and I cant seem to sort the issue. 每次运行代码时,都会遇到“编译错误:预期:列表分隔符或”字样,并且似乎无法解决问题。

'Saves file as an xlsx in directory
ActiveWorkbook.SaveAs Filename:= _
"P:\Desktop\Prior Day Journals\Tueday - Friday\Prior Day Journal" _
& Format(Now() –1,“DD-MMM-YYYY”)“.xlsx” _
FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False

The issue always seems to be surrounding the -1 within the code which should be going back by a day for the file name. 问题似乎总是围绕在代码中的-1周围,而文件名应该回溯一天。

Thanks in advance 提前致谢

In fact, the error is that the you used is not the minus sign - but the UNICODE character EN DASH . 实际上,错误是您使用的不是负号-而是UNICODE字符EN DASH


Another approach would be to use the DateAdd function to do so. 另一种方法是使用DateAdd函数来执行此操作。

You also have a missing & in your concatenation string and a missing , to separate parameters. 您的串联字符串中也有& ,缺少,以分隔参数。

'Saves file as an xlsx in directory
ActiveWorkbook.SaveAs Filename:= "P:\Desktop\Prior Day Journals\Tueday - Friday\Prior Day Journal" _
& Format(DateAdd("d", -1, Now()),"DD-MMM-YYYY") & ".xlsx" _
, FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM