统计211

标题: 搜索文件夹下具有某一sheet名的Excel文件 [打印本页]

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





欢迎光临 统计211 (http://www.tj211.com/) Powered by Discuz! X3.2