我有一个excel文件,其中单元格A1包含公式:
=C:\folder1\[1.xls]Sheet1!A1
并且相对于所有达到H100的细胞。
现在我希望将A1的公式更改为(类似于其他单元格,最高为H100)
=C:\folderA\[A.xls]Sheet1!A1
最初我通过查找和替换语句
录制了一个宏来执行此操作Sub replace()
Application.EnableEvents = False
Application.Calculation = xlCalculationManual
Range("A1:H100").replace What:="folder1\[1.xls]", Replacement:="folderA\[A.xls]", _
LookAt:= xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Application.EnableEvents = True
End Sub
但这需要10多分钟才能完成,在excel的左下角,它显示“链接:---”(正在加载......)
有没有替代方法?
答案 0 :(得分:1)
尝试(只需不到一秒)
Sub ReplaceInaFormula()
Application.ScreenUpdating = False
Application.EnableEvents = False
Application.DisplayAlerts = False
Dim c As Range
For Each c In Range("A1:H100")
c = Replace(c.Formula, "folder1\[1.xls]", "folderA\[A.xls]")
Next
Application.DisplayAlerts = True
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub