how to open latest date in file name

jason1000rr

New Member
Joined
Sep 2, 2016
Messages
14
Hi Everyone--
Looking for guidance to open file with the latest date within its name. Below is what I am working with. I typed "Latest Date" where in name it would go. Name is always recent to current month, but date is older. Any help would be much appreciated. Thank you

Fname = "\\global.corp.net\someplace\someplaceProcurement\IQR\IQR " & LatestDate & ".xlsx"
Set wbb = Workbooks.Open(Filename:=Fname, UpdateLinks:=False, Notify:=False)
For Each wb In Application.Workbooks


I used below for another file I used to work with and it worked for when it was current date. But, not able to figure out for latest date.

Dim curDate As String, Fname As String
curDate = Format(Date, "yyyy-mm-dd")
Dim wba As Workbook, wbb As Workbook, wbc As Workbook, wbd As Workbook, wbe As Workbook, wbf As Workbook, wb As Workbook
Fname = "Y:\Consumables\corporation\DMC\DMC - Planning & Materials\On Hand Reports\DMC Site\" & curDate & "_INV_R12_DMC_Onhandreport.xlsx"
Set wba = Workbooks.Open(Filename:=Fname, UpdateLinks:=False, Notify:=False)
 
You're right, but that's not necessary. The oWs already refers to the chosen sheet; if you insert a line in your code (at "your code goes here") like
.Select
the sheet (tab) will be selected.
Thanks! I tried and tried, but couldn't get it to work. Revised one of the macros I had as below and did it for me. Thanks again

Code:
 Dim ws As Worksheet
    For Each ws In ActiveWorkbook.Worksheets
    If ws.Name Like "*20*" Then ws.Activate
    Next ws
 
Upvote 0

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
You're welcome! I am glad I could be of some help.
Thanks for your feedback.
 
Upvote 0

Forum statistics

Threads
1,217,160
Messages
6,134,964
Members
449,901
Latest member
d2023

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