|
发表于 2017-4-10 18:53
来自手机
|
显示全部楼层
本帖最后由 lss001 于 2017-4-10 20:29 编辑
Sub Dos() '调用Dos搜索文件
Dim sht As Object
Set myFolder = CreateObject("Shell.Application").BrowseForFolder(1, "GetFolder", 0)
myPath = ThisWorkbook.Path & "\"
With CreateObject("Wscript.Shell")
ar = Split(.exec("cmd /c dir/b /s " & Chr(34) & myPath & Chr(34)).StdOut.ReadAll, vbCrLf)
ar = Filter(ar, ".xl", True) '指定搜索文件类型,True包含,False不包含
For i = 0 To UBound(ar)
If ar(i) <> ThisWorkbook.FullName And ar(i) <> "" Then '排除当前文件与空文件
Workbooks.Open Filename:=ar(i) '打开找到文件
Application.DisplayAlerts = False
For Each sht In ThisWorkbook.Worksheets
If sht.Name <> "25.教师年人均发表教学研究论文情况" Then
sht.Delete
End If
Next
Application.DisplayAlerts = True
ActiveWorkbook.Close Savechanges:=True '处理后自动保存文件
End If
Next
End With
End Sub
重要提示运行代码前先备份文件!!! |
|