vba 用当前日期打开文件的宏
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11618583/
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
Macro to open file with Current date
提问by Trying_hard
I am using a macro to open a file that the file name will change each day because of the current date.
我正在使用宏打开一个文件,由于当前日期,该文件名每天都会更改。
File\today_20120723 for today.
今天的文件\today_20120723。
I am trying this but it isn't working. Suggestions
我正在尝试这个,但它不起作用。建议
Dim OpenPath As String
Dim OpenName As String
OpenPath = "N:\File\": OpenName = OpenPath & "today_" VBA.Format (Date, "YYYYMMDD") & ".xlsx"
Workbooks.Open Filename:=OpenPath
Thanks for the help
谢谢您的帮助
回答by LittleBobbyTables - Au Revtheitroad
Multiple lines of code in a single line is really a pain to read.
一行中的多行代码读起来真的很痛苦。
That said, I'm not sure what VBA.Format
is doing in your code, but this should work:
也就是说,我不确定VBA.Format
您的代码在做什么,但这应该有效:
OpenPath = "N:\File\"
OpenName = OpenPath & "today_" & Format(Date, "YYYYMMDD") & ".xlsx"