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

Manipulating Files

                             The FileTypes collection is retained until you execute NewSearch, which clears the collection
                             and places the value of msoFileTypeOfficeFiles in the collection. However, there’s no need to
                             empty the FileTypes collection before adding new entries. If you assign an entry to the FileType   Chapter 13
                             parameter, any existing entries in the FileTypes collection are destroyed and the new entry
                             becomes the first and only entry in the collection. You can then use the Add method of the
                             collection to add more entries. You can use the same type constants that were listed earlier in
                             the chapter.
                             All the code that we have evaluated so far in this section assumes that you know the directory
                             organization of the computer you are searching and can specify the subdirectories that you
                             want to search. If you do not know the structure and need to map it yourself, a utility must be
                             designed to search for files on any computer.

                             The SearchScopes collection provides a mechanism for carrying out the directory mapping
                             process. The following example examines each member of the collection; each member is a
                             SearchScope object.

                             Sub ListSearchScopeOptions()
                                 Dim SS As SearchScope
                                 Dim strMessage As String

                                 For Each SS In Application.FileSearch.SearchScopes
                                    strMessage = strMessage & SS.ScopeFolder.Name & vbTab
                                    strMessage = strMessage & “ Type=“ & SS.Type & vbCr
                                 Next SS

                                 MsgBox strMessage
                             End Sub

                             The SearchScope objects represent the structures you can examine. The Type property identi­
                             fies the category of each structure. The presence of My Computer and Network Places is no
                             surprise. However, notice that Microsoft Outlook is given as another location. Your code
                             should result in a dialog box similar to the one shown in Figure 13-1.










                             Figure 13-1.  The ListSearchScopeOptions procedure result. Your result might vary slightly
                             depending on how your computer is configured.











                                                                                                       287
                                                                                                Part 4:  Advanced VBA
   308   309   310   311   312   313   314   315   316   317   318