Point:APIを使って高速にファイル検索をしたい。
' APIの宣言
Declare Function SearchPath Lib "kernel32.dll" Alias "SearchPathA" _
(ByVal lpPath As String, ByVal lpFileName As String, _
ByVal lpExtension As String, ByVal nBufferLength As Long, _
ByVal lpBuffer As String, lpFilePart As Long) As Long
Sub FindFile()
Dim FileName As String
Dim Extention As String
Dim FoundFilePath As String * 516
Dim FileNamePart As Long
Dim iRet As Long
' ファイル名
FileName = "UNLHA32"
' 拡張子
Extention = ".dll"
' ファイルを検索
iRet = _
SearchPath(vbNullString,
FileName, Extention, _
Len(FoundFilePath),
FoundFilePath, FileNamePart)
' パス名とファイル名を表示
Range("A1") = Left(FoundFilePath, InStr(FoundFilePath,
vbNullChar) - 1)
End Sub |