Run Macro based on *partial* file name within folder

exceljunk

New Member
Joined
Sep 7, 2022
Messages
2
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I have a main folder on my desktop, lets call it 'C:\Users\Desktop\Update'. Within that folder I have 3 additional folder lets call them 'FY21', 'FY22' and 'FY23'. Within each of those subfolders there are 5 XLSX files. I have created a code for each file based on the subfolder they are in. I am trying to run a single macro that will go through the subfolders and run the codes I've created based on the subfolder.

The files within each subfolder have a consistent partial filename followed by unique numbers that are different each week.


Main folder location > 'C:\Users\Desktop\Update'
Sub folder names > 'FY21', 'FY22' and 'FY23'
Partial Names within EACH subfolder > Apple_1234567890, Oranges_9875342716, Berries_4937405736, Lemons_9283741092, Pears_9362537120

FY21 Apple Macro ran only on file name 'Apple' within FY21 sub folder
FY22 Apple Macro ran only on file name 'Apple' within FY22 sub folder
FY23 Apple Macro ran only on file name 'Apple' within FY23 sub folder

FY21 Oranges Macro ran only on file name 'Oranges' within FY21 sub folder
FY22 Oranges Macro ran only on file name 'Oranges' within FY22 sub folder
FY23 Oranges Macro ran only on file name 'Oranges' within FY23 sub folder

etc.
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.

Forum statistics

Threads
1,223,885
Messages
6,175,183
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