Open excel file from a folder which changes name daily

AndyM90

New Member
Joined
Jul 25, 2014
Messages
47
Hi All,

There is a group of excel files which are automatically saved in a folder daily. I would like to be able to automatically open the documents and copy the data out of these into a central file. Normally this is straight forward, but the problem I have is that the folder changes name daily to be workday-1. Is there a way to have the macro search for the folder name = to workday-1 then open the files within it?

Details:

Folder location: "C:\Users\AM\Desktop\Rec\"
Folder name format: YYYYMMDD i.e. todays download is in a folder called 20140901, tomorrow it will be 20140902 etc etc
File name: ABC.xls

So in summary, I want a macro to open a document which has the same name every day, but the folder it is stored in changes. Any ideas if this is possible?

Thanks!
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Try

Code:
Workbooks.Open Filename:="C:\Users\AM\Desktop\Rec\" & Format(Date - 1, "YYYYMMDD") & "\ABC.XLS"
 
Upvote 0
oh actually, will Date-1 work over weekends? So on a Monday the data I need will be a folder named with Friday's date? I've tried to adjust the code to the below, but it searches for a folder date of 18991229.

Code:
" & Format(WorkDay - 1, "YYYYMMDD") & "\ABC.xls

Any ideas?
 
Upvote 0
How about:

Code:
If Format(Date - 1, "DDDD") = "Sunday" Then
    myDate = Format(Date - 3, "YYYYMMDD")
Else
    myDate = Format(Date - 1, "YYYYMMDD")
End If
Workbooks.Open Filename:="C:\Users\AM\Desktop\Rec\" & myDate & "\ABC.XLS"
 
Upvote 0
Thanks Steve, that seems to work. But I'll have to check properly at the weekend. Thanks for the help
 
Upvote 0

Forum statistics

Threads
1,214,901
Messages
6,122,157
Members
449,068
Latest member
shiz11713

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