|
楼主 |
发表于 2019-9-5 13:11
|
显示全部楼层
拼凑的代码,帮忙价格If Then Else 语句,要不碰到没有错误值的EXCEL,他就停止了
Sub 更新()
Dim Fso As Object, Folder As Object, arr$(), m&, i&
Set Fso = CreateObject("Scripting.FileSystemObject")
Set Folder = Fso.GetFolder(ThisWorkbook.Path)
Call GetFiles(Folder, arr, m)
Application.ScreenUpdating = False
Application.DisplayAlerts = False
For i = 1 To m
With Workbooks.Open(arr(i))
Selection.SpecialCells(xlCellTypeFormulas, 16).Select
Selection.ClearContents
ActiveWorkbook.Save
Close 1
End With
Next
Set Folder = Nothing
Set Fso = Nothing
Application.ScreenUpdating = True
MsgBox "更新完毕。"
End Sub
Sub GetFiles(ByVal Folder As Object, arr$(), m&)
Dim SubFolder As Object
Dim File As Object
For Each File In Folder.Files
If File.Name Like "*.xls*" And InStr(File.Name, ThisWorkbook.Name) = 0 Then
m = m + 1
ReDim Preserve arr(1 To m)
arr(m) = File
End If
Next
For Each SubFolder In Folder.SubFolders
Call GetFiles(SubFolder, arr, m)
Next
End Sub
|
|