Write the filename ending on .xlsx from from a master folder that contains many other folders with folders

Silaws

New Member
Joined
Oct 1, 2014
Messages
14
how can i make a VBA code so that it prints all the filname og the files, when they are placed in many different folders.

The folder i looking like this:

  • Name1
    • (...)
  • Name2
    • LV Faste
      • A.xlsx
      • B.xlsx
      • ...
    • LV Lose
      • C.xlsx
      • D.xlsx
      • ...
    • LH Faste
      • E.xlsx
      • F.xlsx
      • ...
    • LH Lose
      • G.xlsx
for now my code looks like this, but i will only print the filename, if all the files are ind the same folder:

VBA Code:
Option Explicit

Sub GetSheet()
    Dim sFilename as String
    Dim sPath as String

    sPath = "C:\Users\silas\Desktop\Time\"
    sFilename = Dir(sPath & "*.xlsx")
    Do While Len(sFilename) > 0
        Debug.Print sFilename
        sFilename = Dir()
    Loop
End Sub

I i want i to print:
  • A.xlsx
  • B.xlsx
  • C.xlsx
  • D.xlsx
  • E.xlsx
  • F.xlsx
  • G.xlsx
and so on.
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.

Forum statistics

Threads
1,213,558
Messages
6,114,296
Members
448,564
Latest member
ED38

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