Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Open files
Hi everyone. I have some code below that opens all files within folders and
subfolders. Is there any way to tell it to ignore files in a folder than contains the word "rollup". So if a folder under the main folder is named "2005 rollup", skip that folder. Thanks! Sub Open_all_files() 'Opens all files in folder AND Subfolders Dim FSO As Scripting.FileSystemObject Dim TopFolder As String Set FSO = New Scripting.FileSystemObject TopFolder = "C:\testfolder" '<<<<<<<<< CHANGE THIS TO TOP FOLDER InnerProc FSO.GetFolder(TopFolder), FSO End Sub Sub InnerProc(F As Scripting.Folder, FSO As Scripting.FileSystemObject) Dim SubFolder As Scripting.Folder Dim OneFile As Scripting.File Dim WB As Workbook For Each SubFolder In F.SubFolders InnerProc SubFolder, FSO Next SubFolder For Each OneFile In F.Files Debug.Print OneFile.Path If Right(OneFile.Name, 4) = ".xls" Then Set WB = Workbooks.Open(Filename:=OneFile.Path) 'Do stuff here End If Next OneFile End Sub |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Open files
If you place
If ucase(F.Name) Like ("rollback") Then Exit Sub above the line For Each SubFolder In F.SubFolders then that will skip all files in that folder, but still check for subfolders in that folder. Alternatively, if you replace InnerProc SubFolder, FSO with If not ucase(F.Name) Like ("rollback") Then InnerProc SubFolder, FSO then it will check all files and subfolders. HTH, Gareth Steph wrote: Hi everyone. I have some code below that opens all files within folders and subfolders. Is there any way to tell it to ignore files in a folder than contains the word "rollup". So if a folder under the main folder is named "2005 rollup", skip that folder. Thanks! Sub Open_all_files() 'Opens all files in folder AND Subfolders Dim FSO As Scripting.FileSystemObject Dim TopFolder As String Set FSO = New Scripting.FileSystemObject TopFolder = "C:\testfolder" '<<<<<<<<< CHANGE THIS TO TOP FOLDER InnerProc FSO.GetFolder(TopFolder), FSO End Sub Sub InnerProc(F As Scripting.Folder, FSO As Scripting.FileSystemObject) Dim SubFolder As Scripting.Folder Dim OneFile As Scripting.File Dim WB As Workbook For Each SubFolder In F.SubFolders InnerProc SubFolder, FSO Next SubFolder For Each OneFile In F.Files Debug.Print OneFile.Path If Right(OneFile.Name, 4) = ".xls" Then Set WB = Workbooks.Open(Filename:=OneFile.Path) 'Do stuff here End If Next OneFile End Sub |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
emailing files from excel, the files will not go until I open up . | New Users to Excel | |||
how do I toggle between 2 open excel files and leave both open | Excel Discussion (Misc queries) | |||
How to change default Open/Files of Type to "Microsoft Excel Files | Excel Discussion (Misc queries) | |||
I cant open files unless I open the Excel program first | Excel Discussion (Misc queries) | |||
file open via IE hyperlink causes already open files to shrink and tile | Setting up and Configuration of Excel |