Home |
Search |
Today's Posts |
#10
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() MCSDPhil Hi there, I had to have a go and see if I could do the iteration through files and subfolders code and make it work. This seems to work ok. Sub LoopThroughFiles() ' ' Keyboard Shortcut: Ctrl+c ' Dim strBaseFolder As String Dim strFolder As String Dim intResult As Integer 'CHANGE THIS TO YOUR BASE FOLDER PATH strBaseFolder = "C:\Documents and Settings\user\My Documents\Personal\Tests\" IterateFilesAndFolders strBaseFolder End Sub Function IterateFilesAndFolders(ByVal strFolder As String) Dim strFileOrFolder As String Dim colFolders As New Collection Dim varSubFolder As Variant Debug.Print "strFolder=" & strFolder 'Loop through files strFileOrFolder = Dir(strFolder, vbDirectory) Do While strFileOrFolder < "" If strFileOrFolder < "." And strFileOrFolder < ".." Then If (GetAttr(strFolder & strFileOrFolder) And vbDirectory) = vbDirectory Then Debug.Print ("Folder:" & strFileOrFolder & vbCrLf) colFolders.Add strFileOrFolder, strFileOrFolder Else Debug.Print ("File:" & strFileOrFolder & vbCrLf) If UCase(strFileOrFolder) = "VOLUME.XLS" Then Debug.Print ("VOLUME.XLS Found" & vbCrLf) 'PUT YOUR OPEN AND SAVE CODE HERE End If End If End If strFileOrFolder = Dir() Loop For Each varSubFolder In colFolders IterateFilesAndFolders strFolder & CStr(varSubFolder) & "\" Next End Function The IterateFilesAndFolders function is called recursively, i.e. it is a function that calls itself, to get at the files in the subfolders etc. Regards, Phil. *** Sent via Developersdex http://www.developersdex.com *** |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
workbook open in looping | Excel Programming | |||
Looping through list of workbooks to open & sheets to move | Excel Programming | |||
Looping thru open word documents to find a specific one | Excel Programming | |||
Looping folder changing - Save Preview Picture | Excel Programming | |||
VBA code for looping through open workbooks and worksheets | Excel Programming |