Download Folder Names into an Excel sheet

Nick70

Board Regular
Joined
Aug 20, 2013
Messages
207
Hi,

What I need to do is quite simple.

I need to check that all clients have a specific sub-folder created for them in a specific folder (called Client Names) found in a directory.

I therefore need to download all the client sub-folders found in that folder (i.e. Client Names) to see if they match with my client list.
Every client sub-folder contains some excel files but I am NOT interested in these I only want the full list of client sub-folder names (each of which corresponds to a client name).

Folder 'Client Names' which contains client sub-folders is found in directory below:

C:\Users\user\OneDrive\Desktop\Client Names

Can you please let me know if there is an excel formula or a macro which can go into the directory look into 'Client Names' folder and return a list in an excel sheet of all sub-folders contained in it (i.e. the client names)?

Thanks,
Nic
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.

Marc L

Well-known Member
Joined
Apr 5, 2021
Messages
1,633
Office Version
  1. 2010
Platform
  1. Windows

Nick70

Board Regular
Joined
Aug 20, 2013
Messages
207
Hi,

The original question from the thread you sent says:

'I need a macro to brings all files from folder and subfolders to multiple columns..."

What I need and I mentioned this in my email is not file names but folder names.

Is there a macro to extract folder names as opposed to file names?

Thanks,
Nic
 

Marc L

Well-known Member
Joined
Apr 5, 2021
Messages
1,633
Office Version
  1. 2010
Platform
  1. Windows
Yes like in the link where in posts #2 & 8 each code extracts first only the directories name, so just read & see …​
A must see in VBA help : Dir function …​
 

DanteAmor

Well-known Member
Joined
Dec 3, 2018
Messages
13,773
Office Version
  1. 2007
Platform
  1. Windows

ADVERTISEMENT

Run this macro, the folder names will stay on the active sheet in cell A2 and down.

VBA Code:
Sub subfolders()
  Dim sPath As String, DirFile As String
  Dim i As Long
  
  sPath = "C:\Users\user\OneDrive\Desktop\Client Names\"
  DirFile = Dir(sPath, vbDirectory)
  i = 2
  Do While DirFile <> ""
    If DirFile <> "." And DirFile <> ".." And _
      ((GetAttr(sPath & DirFile) And vbDirectory) = 16) Then
      Range("A" & i).Value = DirFile
      i = i + 1
    End If
    DirFile = Dir
  Loop
End Sub
 
Solution

DanteAmor

Well-known Member
Joined
Dec 3, 2018
Messages
13,773
Office Version
  1. 2007
Platform
  1. Windows
I'm glad to help you. Thanks for the feedback.
 

Forum statistics

Threads
1,144,673
Messages
5,725,701
Members
422,636
Latest member
GatorsBucs

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
Top