I'm able to loop through all the files in a directory but what i need to do is loop through all the folders, within a folder and where that folder is called "Q2 2012" open the file within that folder and execute code.
There are several Q2 2012 folders but are all at different levels within the directory folder? The code i have below might be a distraction so happy to work from afresh. FYI it 2007 so application file search won't work!
Be very grateful for you assistance.
Sub InterlockSalesVolumeDataPull()
Dim oWbk As Workbook
Dim sFil As String
Dim sPath As String
Dim wrk1 As Worksheet
Dim wsheet As Worksheet
Dim BothFileTypesComplete As Boolean
Dim FirstFileTypefinished As Boolean
Dim FirstSheet As Integer
Dim a As Integer
Dim FileSelect As String
Dim oSheet As Worksheet
FileSelect = ThisWorkbook.Sheets("Activity capture.").Range("c1")
a = 5
FirstSheet = 1
Application.ScreenUpdating = False
Application.DisplayAlerts = False 'turn off prompt messages
'sPath = "N:\Marketing Strategy Team\Quarterly CMU Submissions\Product & Channel submissions\" & FileSelect 'location of files
'sPath = "\\Fillpb3cah38214\D_MarkPlan0001$\Marketing Strategy Team\Quarterly CMU Submissions\Product & Channel submissions\" '& FileSelect
sPath = "\\Fillpb3cah38214\D_MarkPlan0001$\Marketing Strategy Team\Quarterly CMU Submissions\Product & Channel submissions\Products\Cards\"
ChDir sPath
sFil = Dir("*.xls") 'change or add formats
Do While sFil <> "" 'will start LOOP until all files in folder sPath have been looped through
Set oWbk = Workbooks.Open(sPath & "\" & sFil, 0) 'opens the file
oWbk.Activate 'actives workbook to allow ammends to be made
Dim Brand As String
Brand = ActiveWorkbook.ActiveSheet.Name
'loop through sheets
For Each wsheet In ActiveWorkbook.Worksheets
wsheet.Activate
Dim SheetName As String
SheetName = ActiveSheet.Name
If ActiveSheet.Name <> "Cover page" Then
ThisWorkbook.Activate
Worksheets(SheetName & " Interlock Data").Delete ' remove old sheet
oWbk.Activate
Cells.Select
Cells.Copy
ThisWorkbook.Activate
'Set oSheet = Worksheets.Add
ThisWorkbook.Sheets.Add After:=Sheets(Worksheets.Count), Count:=1, Type:=xlWorksheet
With ActiveSheet
.Name = SheetName & " Interlock Data"
.Tab.Color = RGB(255, 0, 0)
End With
ActiveSheet.Paste
End If
Next wsheet
oWbk.Close 'close the workbook, saving changes
sFil = Dir
Loop ' End of LOOP
Application.DisplayAlerts = True 'turn on prompt messages
Application.ScreenUpdating = True
End Sub
There are several Q2 2012 folders but are all at different levels within the directory folder? The code i have below might be a distraction so happy to work from afresh. FYI it 2007 so application file search won't work!
Be very grateful for you assistance.
Sub InterlockSalesVolumeDataPull()
Dim oWbk As Workbook
Dim sFil As String
Dim sPath As String
Dim wrk1 As Worksheet
Dim wsheet As Worksheet
Dim BothFileTypesComplete As Boolean
Dim FirstFileTypefinished As Boolean
Dim FirstSheet As Integer
Dim a As Integer
Dim FileSelect As String
Dim oSheet As Worksheet
FileSelect = ThisWorkbook.Sheets("Activity capture.").Range("c1")
a = 5
FirstSheet = 1
Application.ScreenUpdating = False
Application.DisplayAlerts = False 'turn off prompt messages
'sPath = "N:\Marketing Strategy Team\Quarterly CMU Submissions\Product & Channel submissions\" & FileSelect 'location of files
'sPath = "\\Fillpb3cah38214\D_MarkPlan0001$\Marketing Strategy Team\Quarterly CMU Submissions\Product & Channel submissions\" '& FileSelect
sPath = "\\Fillpb3cah38214\D_MarkPlan0001$\Marketing Strategy Team\Quarterly CMU Submissions\Product & Channel submissions\Products\Cards\"
ChDir sPath
sFil = Dir("*.xls") 'change or add formats
Do While sFil <> "" 'will start LOOP until all files in folder sPath have been looped through
Set oWbk = Workbooks.Open(sPath & "\" & sFil, 0) 'opens the file
oWbk.Activate 'actives workbook to allow ammends to be made
Dim Brand As String
Brand = ActiveWorkbook.ActiveSheet.Name
'loop through sheets
For Each wsheet In ActiveWorkbook.Worksheets
wsheet.Activate
Dim SheetName As String
SheetName = ActiveSheet.Name
If ActiveSheet.Name <> "Cover page" Then
ThisWorkbook.Activate
Worksheets(SheetName & " Interlock Data").Delete ' remove old sheet
oWbk.Activate
Cells.Select
Cells.Copy
ThisWorkbook.Activate
'Set oSheet = Worksheets.Add
ThisWorkbook.Sheets.Add After:=Sheets(Worksheets.Count), Count:=1, Type:=xlWorksheet
With ActiveSheet
.Name = SheetName & " Interlock Data"
.Tab.Color = RGB(255, 0, 0)
End With
ActiveSheet.Paste
End If
Next wsheet
oWbk.Close 'close the workbook, saving changes
sFil = Dir
Loop ' End of LOOP
Application.DisplayAlerts = True 'turn on prompt messages
Application.ScreenUpdating = True
End Sub