简体   繁体   English

更改外部链接时VBA运行速度非常慢

[英]VBA runs very slow on changing external link

I have a excel file in which cell A1 contains the formula: 我有一个excel文件,其中单元格A1包含公式:

=C:\folder1\[1.xls]Sheet1!A1

and relatively for all cells up to H100. 并且相对于所有单元都高达H100。

Now I wish to change the formula for A1 to (similarly for other cells up to H100) 现在我希望将A1的公式更改为(类似于其他单元格,最高可达H100)

=C:\folderA\[A.xls]Sheet1!A1

Originally I recorded a macro to do this by a find and replace statement 最初我通过查找和替换语句记录了一个宏

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

But it takes over 10 minutes to do that and on the bottom-left corner of excel, it says "Link: ---" (loading...) 但这需要10多分钟,在excel的左下角,它显示“链接:---”(正在加载...)

Are there any alternative method? 有没有替代方法?

Try that ( it takes less than a second ) 试试( 需要不到一秒钟

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM