批量替换多工作薄内指定内容

  • A+
所属分类:好好学习

遍历当前文件夹,替换多个工作薄内指定内容:

VBA
Sub 替换指定内容()
Dim MyPath$, MyName$, sh As Worksheet
Application.ScreenUpdating = False
MyPath = ThisWorkbook.Path & "\"
MyName = Dir(MyPath & "*.xlsx")
Do While MyName <> ""
If MyName <> ThisWorkbook.Name Then
With Workbooks.Open(MyPath & MyName)
For Each sh In .Sheets
sh.UsedRange.Replace "1#", "A#"
sh.UsedRange.Replace "2#", "B#"
sh.UsedRange.Replace "3#", "C#", xlPart
Next
.Close True
End With
End If
MyName = Dir
Loop
Application.ScreenUpdating = True
MsgBox "替换完毕"
End Sub

 

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: