Office VBA教程:FileTypes属性



expression   必需。该表达式返回“应用于”列表中的对象之一。


本示例搜索 C:\ 驱动器上的所有 HTML 和 Microsoft Excel 文件。

Sub SearchForFiles()
    'Declare a variable to act as a generic counter.
    Dim lngCount As Long
    'Use a With...End With block to reference the
    'FileSearch object.
    With Application.FileSearch
        'Clear all the parameters of the previous searches.
        'This method doesn't clear the LookIn property or
        'the SearchFolders collection.
        'Setting the FileType property clears the
        'FileTypes collection and sets the first
        'item in the collection to the file type
        'defined by the FileType property.
        .FileType = msoFileTypeWebPages
        'Add a second item to the FileTypes collection.
        .FileTypes.Add msoFileTypeExcelWorkbooks
        'Display the number of FileTypes objects in the collection.
        MsgBox "You are about to search for " & .FileTypes.Count & _
            " file types."
        'Set up the search to look in all subfolders on the C:\ drive.
        .LookIn = "C:\"
        .SearchSubFolders = True
        'Execute the search and test to see if any files
        'were found.
        If .Execute <> 0 Then
            'Display the number of files found.
            MsgBox "Files found: " & .FoundFiles.Count
            'Loop through the list of found files and
            'display the path of each one in a message box.
            For lngCount = 1 To .FoundFiles.Count
                If MsgBox(.FoundFiles.Item(lngCount), vbOKCancel, _
                    "Found files") = vbCancel Then
                    'Break out of the loop
                    lngCount = .FoundFiles.Count
                End If
            Next lngCount
            MsgBox "No files found."
        End If
    End With
End Sub

上页:Office VBA教程:FileType属性 下页:Office VBA教程:FilterIndex属性

Office VBA教程:FileTypes属性

Office VBA教程:FilterIndex属性 Office VBA教程:Filters属性
Office VBA教程:FixedWidthFont属性 Office VBA教程:FixedWidthFontSize属性
Office VBA教程:FoundFiles属性 Office VBA教程:GuessHelp属性
Office VBA教程:Guid属性 Office VBA教程:Heading属性
Office VBA教程:Height属性 Office VBA教程:HelpContextId属性
Office VBA教程:HelpFile属性 Office VBA教程:HighPriorityTips属性
Office VBA教程:HTMLProjectItems属性 Office VBA教程:HyperlinkType属性
Office VBA教程:Icon属性 Office VBA教程:Id属性
Office VBA教程:Index属性 Office VBA教程:InitialFileName属性
Office VBA教程:InitialView属性 Office VBA教程:Introduction属性
版权所有 © 中山市飞娥软件工作室 证书:粤ICP备09170368号