制作包含日期的文件名 (VBA)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10123250/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Make file name containing date (VBA)
提问by Arul Servin
I want to save a file in a directory, and the filename should have this format:
我想将文件保存在目录中,文件名应具有以下格式:
iTerm Metrics Report Apr 12
i.e. the root file name "iTerm Metrics Report", followed by today's date formatted as three-letter month followed by day of the month.
即根文件名“iTerm Metrics Report”,后面是今天的日期,格式为三个字母的月份,后面是月份中的某一天。
How do I make such a filename?
我如何制作这样的文件名?
回答by Siddharth Rout
sFile = "iTerm metrics Report" & "" & Format(Date) & ".xls" ActiveWorkbook.SaveAs Filename:="C:\Documents and Settings\706849\My Documents\Metric Report\" & sFile – Arul Servin 5 secs ago
sFile = "iTerm 指标报告" & "" & Format(Date) & ".xls" ActiveWorkbook.SaveAs Filename:="C:\Documents and Settings\706849\My Documents\Metric Report\" & sFile – Arul Servin 5 秒前
Is this what you are trying?
这是你正在尝试的吗?
sFile = "iTerm metrics Report " & Format(Date,"mmm yy") & ".xls"
FOLLOWUP
跟进
Thank you...but am trying for Date (Apr 12) 12 is a date not a year...Please suggest me accordingly...thanks – Arul Servin 55 secs ago
谢谢……但是我正在尝试日期(4 月 12 日)12 是一个日期而不是一年……请相应地建议我……谢谢 – Arul Servin 55 秒前
In that case change the code to
在这种情况下,将代码更改为
sFile = "iTerm metrics Report " & Format(Date,"mmm dd") & ".xls"

