Home » excel » excel – Macro to open file with Current date

excel – Macro to open file with Current date

Posted by: admin May 14, 2020 Leave a comment

Questions:

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.

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

How to&Answers:

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:

OpenPath = "N:\File\"
OpenName = OpenPath & "today_" & Format(Date, "YYYYMMDD") & ".xlsx"