Loop through folders and open folder whose name matches with yesterdays month.

hopeful_positive

New Member
Joined
Jan 20, 2018
Messages
6
Hello all,

I am new to VBA coding. I had taken a programming course almost 6 years ago and never touched it since but I would like to start learning slowly to automate a lot of my excel stuff.


I have 18 folders at a particular location in my drive. Out of the 18 files, 12 are files with names of the months in a calendar year such as January, February, March.... etc. .. December and the rest are folders that I do not need to worry about.

Via VBA code, I am hoping to access that monthly folder only which matches the month of the previous day, for example, if today was 1st of May, I would like to loop through all the folders in that location and open/access/look within the folder whose name matches the month of yesterdays date which would be 30th of April so April folder.

Requesting your kindest help.

Thank you !
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
No need to loop. You can get the full path of the required month folder like this:
Code:
    Dim monthFolder As String
    monthFolder = "C:\path\to\main\folder\" & Format(Date - 1, "Mmmm")
    MsgBox monthFolder
 
Upvote 0

Forum statistics

Threads
1,223,246
Messages
6,170,988
Members
452,373
Latest member
TimReeks

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