|
三戒 发表于 2009-5-23 14:16
你的代码怎么和我的不一致?::L
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 = 1 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 = "没有查找到需要的文件"
End Function
Private Sub CommandButton1_Click()
Dim k&
With Application.SearchFile
For N = 1 To 6
k = Range("A65536").End(xlUp).Row
.NewSearch
.LookIn = Chr$(N + 65) & ":"
.SearchSubFolders = True
.Filename = "报账2014.xls"
.FileType = msoFileTypeAllFiles
If .Execute() > 0 Then
For i = 1 To .FoundFiles.Count
Cells(i + k, 1) = .FoundFiles(i)
Next i
End If
Next
End With
End Sub
请教我这个脚本要在2007里面运行,需要怎样改脚本? |
|