For Each folder, workbook, worksheet

Paul Morris

Board Regular
Joined
Sep 27, 2004
Messages
64
Hi All,

Am looking to get pieces of data from each tab of multiple workbooks in multiple folders - e.g. there are 5 folders (A, B, C, D, E) sitting under C:\Stuff, and each of these folders have 4 workbooks.

How do I use the for each statement with respect to folders, and workbooks?

Cheers,
Paul
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Thanks - except now the variable "File" returns a filename of a file on my desktop, not a file from the specified pathname (have checked, and it does recognise that the pathname is as it should be). Any idea why this is happening?



Sub UpdateSummary()

Dim w As Workbook
Dim wb As Workbook
Dim File As String
Dim uPath As String
Dim UpdateFolder As String
Dim s As Worksheet

Set w = ThisWorkbook
Set s = w.Sheets(1)

UpdateFolder = s.Range("J1")

uPath = w.Path
File = "a"


Do While File <> ""
ChDir uPath & "\" & UpdateFolder
File = Dir("")
Set wb = Workbooks.Open(uPath & "\" & UpdateFolder & "\" & File)
 
Upvote 0

Forum statistics

Threads
1,215,522
Messages
6,125,312
Members
449,218
Latest member
Excel Master

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