VBA to open file with partial name

three482

New Member
Joined
Jul 9, 2024
Messages
9
Office Version
  1. 365
Platform
  1. Windows
Hi everyone.

I’m trying to build a macro that will open the most recent file (“Daily Report.”)

The problem is - the file is always saved as “\DailyReport_yyyymmdd” followed by a series of numbers representing a time stamp when the file was created. Unfortunately, the report can be run at different times, so while the end of the file always starts with “Daily Report,” and I can add an input box to enter the date (since older files are periodically needed), I need something that will ignore the last six characters between the date and .CSV.

Thanks in advance!
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
You said "time stamp when the file was created" but you also said that you can enter any date you want, so it might not be the date the file was created. How are you defining "most recent file"? The one with the most recent yyyymmdd date, or the one that was created most recently (since you can create files with old dates)?

Also you saved the most important part as your very last word. Is the full file name format DailyReport_yyyymmdd.csv?

If you have any code right now it would be helpful to provide all of that so whatever we give you will be compatible. (Please use code tags when pasting code into a post.)
 
Upvote 0

Forum statistics

Threads
1,223,882
Messages
6,175,164
Members
452,615
Latest member
bogeys2birdies

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top