2019excel。怎么用VBA代码,批量编辑修改文件?

2024-11-19 04:14:49
推荐回答(2个)
回答(1):

Excel怎样快速批量将相同表式多文件数据修改

回答(2):

Option Explicit
Sub test() '新建工作簿,与文件夹一起放在同一目录下
Dim p$, fd, f$, sh As Worksheet
Application.ScreenUpdating = False
For Each fd In CreateObject("Scripting.FileSystemObject").GetFolder(ThisWorkbook.Path).SubFolders
p = fd & "\"
f = Dir(p & "*.xls*")
Do While f <> ""
If f <> ThisWorkbook.Name Then
With Workbooks.Open(p & f, 0)
For Each sh In .Worksheets
sh.Cells.Replace "正常", "1", xlWhole
sh.Cells.Replace "异常", "2", xlWhole
Next
.Close 1
End With
End If
f = Dir
Loop
Next
Application.ScreenUpdating = True
End Sub