Excel dynamic filename

I have an excel file with name data report y21m12d13. Every day I create a new one. For today for example will be report data y21m12d14. How I can in excel application scope to read the last file Every time and save in new excel file that in filename increase the number by one?

Thank you!


Let’s say PrevFile is

              PrevFile = "y"+Now.AddDays(-1).ToString("yy")+"m"+Now.AddDays(-1).ToString("MM")+"d"+Now.AddDays(-1).ToString("dd")

And then in Excel Application scope mention as below to read previous day file.


Create current day file name as below.

        CurrFile = "y"+Now.ToString("yy")+"m"+Now.ToString("MM")+"d"+Now.ToString("dd")

Note: Replaced mm with MM


“mm” means minute, so we should use “MM” instead of “mm” as the following.



1 Like

Thank you both for your support and fast reaction!

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.