|
Private Sub CommandButton1_Click()
Dim myPath$, myFile$, AK As Workbook, aRow%, tRow%, i As Integer
Application.ScreenUpdating = False '冻结屏幕,以防屏幕抖动
myPath = ThisWorkbook.Path & "\" '把文件路径定义给变量
myFile = Dir(myPath & "*.xls") '依次找寻指定路径中的*.xls文件
Do While myFile <> "" '当指定路径中有文件时进行循环
If myFile <> ThisWorkbook.Name Then
Set AK = Workbooks.Open(myPath & myFile) '打开符合要求的文件
m = ActiveSheet.UsedRange.Rows.Count
n = ActiveSheet.UsedRange.Columns.Count
AK.ActiveSheet.Range("A1").Resize(m, n).Replace What:="A", Replacement:="b", LookAt:=xlPart, MatchCase:=False, MatchByte:=False
AK.ActiveSheet.Range("A1").Resize(m, n).Replace What:="s", Replacement:="d", LookAt:=xlPart, MatchCase:=False, MatchByte:=False
AK.ActiveSheet.Range("A1").Resize(m, n).Replace What:="f", Replacement:="g", LookAt:=xlPart, MatchCase:=False, MatchByte:=False
Workbooks(myFile).Close savechanges:=True '关闭源工作簿
End If
myFile = Dir '找寻下一个*.xls文件
Loop
Application.ScreenUpdating = True '冻结屏幕,此类语句一般成对使用
MsgBox "替换完成,请查看!", 64, "提示"
End Sub
解压后不要放在需要替换的文件夹内
点击按钮
选择需要进行替换的文件夹
|
|