Help! Looking for a macro to open a file whose name changes every week

nlmtz80

New Member
Joined
Aug 9, 2018
Messages
2
Hi All,

I am trying to write a macro which opens a spreadsheet, whose name has a prefix which stays the same, but the date (mm.dd.yy) changes every week with the following format: ON_mm.dd.yy.xlsx

I.e This weeks name is 'ON_08.08.18.xlsx' and last weeks name is 'ON_08.01.18.xlsx'.

The report is created every Wednesday and refers to the previous weeks reports.

Thanks!:confused::confused::confused:
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
this works for me, adjust as needed:

place formula in cell A1 to get Wednesday date of the current week
Code:
=CONCATENATE("ON_",TEXT(TODAY()-WEEKDAY(TODAY(),3)+2,"mm.dd.yyyy"))

and macro
Code:
Sub OpenWB()
Dim WB2 As Workbook
Dim MyURL As String
Dim MyFile As String


    MyPath = "c:\testing\"
    MyURL = Range("A1").Value
    MyFile = MyPath & MyURL & ".xlsb"


    Set WB2 = Workbooks.Open(MyFile)


End Sub
 
Upvote 0

Forum statistics

Threads
1,224,747
Messages
6,180,716
Members
452,995
Latest member
isldboy

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