Page 315 - Microsoft Office Excel 2003 Programming Inside Out
P. 315

Manipulating Files

                                    End Select
                                 Next SS
                                                                                                             Chapter 13
                                 MsgBox strMessage

                             End Sub
                             The code will return a result similar to Figure 13-2.






















                             Figure 13-2.  Here is the ListScopeFolderObjects procedure result. Your result might vary
                             depending on how your computer is configured.

                             The Select Case statements were used to isolate and examine each of the top-level structures.
                             Each top-level ScopeFolders collection contains ScopeFolder objects that represent the root
                             directories of the file structures available to it. Each of these ScopeFolder objects contains
                             another ScopeFolders collection that represents the subdirectories under it. This provides a
                             way to navigate through the directory trees.
                             The SearchFolders collection defines additional directory paths to be searched by adding
                             ScopeFolder objects to the collection. SearchFolders is not like the FileTypes collection that is
                             recreated when you assign a value to the FileType property. SearchFolders isn’t affected when
                             you assign a value to the LookIn property or when you execute NewSearch. The LookIn value
                             is additional to the SearchFolders entries.
                             The SearchFolders collection is also retained in the current Excel session, so empty the collec­
                             tion before executing a new search. Remember to empty the SearchFolders collection by loop­
                             ing through each ScopeFolder object and removing it. Review the following example to get a
                             better understanding of how to search through all subdirectories in the root directory of the
                             C drive. When it finds a directory starting with the characters Product, it will add the direc­
                             tory to the SearchFolders collection.






                                                                                                       289
                                                                                                Part 4:  Advanced VBA
   310   311   312   313   314   315   316   317   318   319   320