全硬盘高速查找指定文件

Private Declare Function SearchTreeForFile Lib "ImageHlp.dll" (ByVal lpRoot As String, ByVal lpInPath As String, ByVal lpOutPath As String) As Long
Private Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" (ByVal nDrive As String) As Long
Function SearchFile(ByVal Filename As String) As String
    Dim R As Long, i As Long, SearchPath As String
    For i = 0 To 25
    SearchPath = Chr$(i + 65) & ":/"
    If GetDriveType(SearchPath) = 3 Then
        SearchFile = String$(1024, 0)
        R = SearchTreeForFile(SearchPath, Filename, SearchFile)
        If R <> 0 Then SearchFile = Split(SearchFile, Chr(0))(0): Exit Function
        End If
    Next
    SearchFile = "Can't find it is this system"
End Function

Sub macro1()
    Dim F As String
    F = InputBox("Please input a filename to search", "Infomation", "excel.exe")
    MsgBox SearchFile(F)
End Sub 

你可能感兴趣的:(VBA,其他技巧,API)