hellfire45
Active Member
- Joined
- Jun 7, 2014
- Messages
- 464
Hi guys, Ya'll are usually really good at the puzzly trouble shooting and I'm looking for some assistance.
My goal is to get this to loop through the folder at the path ultimately stored in STRFOLDER but it keeps opening and closing the same excel file in the folder instead of looping through the 70 or so files in the folder. Any idea of how to get it to move onto the next file in the folder until it has hit every file? Thanks guys, I'm sure its something really small but I just can't quite figure it out.
My goal is to get this to loop through the folder at the path ultimately stored in STRFOLDER but it keeps opening and closing the same excel file in the folder instead of looping through the 70 or so files in the folder. Any idea of how to get it to move onto the next file in the folder until it has hit every file? Thanks guys, I'm sure its something really small but I just can't quite figure it out.
VBA Code:
upath = Application.ActiveWorkbook.Path
i = 0
Do
srcpath = upath & "\" & Format(Date - i, "yyyy mm dd")
If Dir(srcpath & "\", vbDirectory) <> "" Then
Exit Do
Else
i = i + 1
End If
Loop Until i = 35
FolderNames = Array("AM\", "VP\")
For Each Folder In FolderNames
STRFOLDER = srcpath & "\" & Folder
strFileSpec = STRFOLDER & "*.*"
Set fso = CreateObject("Scripting.FileSystemObject")
File_iteration = 0
err_count = 0
file_counter.CountFiles
For Each FileInFolder In fso.getfolder(STRFOLDER).Files
On Error GoTo nextfile:
File_iteration = File_iteration + 1 'keeps track of the iteration of files being processed
Application.StatusBar = File_iteration - 1 & " of " & j & " Files Processed. Please be Patient."
strFileName = Dir(strFileSpec)
sFile = Dir(STRFOLDER & strFileName)
If Folder = "AM\" Then
Workbooks.Open STRFOLDER & sFile, ReadOnly:=True
sheet_num = ActiveWorkbook.Sheets.Count
For x_sheet = 2 To sheet_num
Set wscs = ActiveWorkbook.Sheets(x_sheet)
'a whole bunch of worksheet processes stuff
next
Next
ActiveWorkbook.Close False
End If
loopsetter:
Next FileInFolder 'next iteration in loop
Next Folder