Excel VBA to insert variable Parent and Subfolder names into different cells

rampaige

New Member
Joined
Aug 30, 2020
Messages
1
Office Version
  1. 2019
Platform
  1. Windows
Hi everyone.

I’m looking for an Excel VBA to insert the subfolder name and one folder before that (parent folder) in separate cells such as A1 and A2.
Example:
I have saved Book1.xlsm in the following directory:
C:\Users\Matthew\Downloads\F23343\29035020\Book1.xlsm


** Important**: The directory path (last two folders names) would be changed for each Excel sheet. For example, new Excel sheet could be saved in a different directory such as C:\Users\Matthew\Downloads\Z0253343\27654020\Book1.xlsm

So, the code shouldn’t only rely on these names and directory.

In this case, I need the VBA code to insert 29035020 and F23343 names into two separate cells. Also, for the F23343, is there any way to exclude the letter F and only insert 23343?

Your help is highly appreciated. Thanks
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)

Forum statistics

Threads
1,214,389
Messages
6,119,232
Members
448,879
Latest member
VanGirl

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