搜索文件夹下具有某一sheet名的Excel文件
直接上代码了。
1 sub fileFind()
2 'filepath to be found
3 folder="D:/PathofFindFile"
4 'sheet name to be found
5 findSheetName="FindSheetName"
6 With Application.FileSearch
7 .NewSearch
8 .LookIn=folder
9 .FileType=msoFileTypeExcelWorkbooks
10 If .Execute>1 Then
11 For i=1 to .FoundFiles.Count
12 'open the excel file
13 Set eachBook=Workbooks.Open(.FoundFiles(i))
14 For j=1 To eachBook.Worksheets.Count
15 If UCase(eachBook.Worksheets(j).Name)=findSheetName
16 'process after being found
17 End If
18 Next j
19 eachBook.Close
20 Next i
21 End If
22 End With
23 End sub
24
2 'filepath to be found
3 folder="D:/PathofFindFile"
4 'sheet name to be found
5 findSheetName="FindSheetName"
6 With Application.FileSearch
7 .NewSearch
8 .LookIn=folder
9 .FileType=msoFileTypeExcelWorkbooks
10 If .Execute>1 Then
11 For i=1 to .FoundFiles.Count
12 'open the excel file
13 Set eachBook=Workbooks.Open(.FoundFiles(i))
14 For j=1 To eachBook.Worksheets.Count
15 If UCase(eachBook.Worksheets(j).Name)=findSheetName
16 'process after being found
17 End If
18 Next j
19 eachBook.Close
20 Next i
21 End If
22 End With
23 End sub
24