Download Folder Names into an Excel sheet

Nick70

Board Regular
Joined
Aug 20, 2013
Messages
212
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

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"

Marc L

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

Nick70

Board Regular
Joined
Aug 20, 2013
Messages
212
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,769
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
14,183
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
14,183
Office Version
  1. 2007
Platform
  1. Windows
I'm glad to help you. Thanks for the feedback.
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,152,119
Messages
5,768,221
Members
425,460
Latest member
Astros1243

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