VBA.ChangeLink问题

VBA.ChangeLink问题,vba,excel,excel-2010,Vba,Excel,Excel 2010,我面临一个非常奇怪的VBA代码问题。我有一个excel文件,它使用来自加载项的UDF。这个文件在服务器上运行,所以我真的不可能看到代码中到底发生了什么。现在,无论何时(在本地计算机上)对文件进行任何更改,我都使用本地版本的加载项。因此,在替换服务器上的文件时,我需要它自动更改指向服务器上的加载项副本的链接。为此,我在文件中有以下代码: Private Sub changeLinks(addinName As String, wb As Workbook) Dim check As Long Di

我面临一个非常奇怪的VBA代码问题。我有一个excel文件,它使用来自加载项的UDF。这个文件在服务器上运行,所以我真的不可能看到代码中到底发生了什么。现在,无论何时(在本地计算机上)对文件进行任何更改,我都使用本地版本的加载项。因此,在替换服务器上的文件时,我需要它自动更改指向服务器上的加载项副本的链接。为此,我在文件中有以下代码:

Private Sub changeLinks(addinName As String, wb As Workbook)
Dim check As Long
Dim i As Long
Dim existingPath As String
Dim correctPath As String
Dim temp As Variant
Dim tempA As Variant
Application.DisplayAlerts = False
Application.AskToUpdateLinks = False
Application.ScreenUpdating = False
temp = getLinks(addinName, wb)
On Error Resume Next
    correctPath = Application.AddIns(addinName).fullName
    For i = 1 To 100
        If temp(i) = "" Then Exit For
        If UCase(temp(i)) <> UCase(correctPath) Then
            wb.ChangeLink temp(i), correctPath, xlLinkTypeExcelLinks
        End If
    Next
On Error GoTo 0
End Sub

Private Function getLinks(addinName As String, wb As Workbook)
Dim allLinks As Variant
Dim check As Long
Dim i As Long
Dim temp(1 To 100) As Variant
Dim linkCounts As Long
check = 0
allLinks = wb.LinkSources
linkCounts = 0
On Error Resume Next
For i = LBound(allLinks) To UBound(allLinks)
    check = InStr(1, UCase(allLinks(i)), UCase(addinName))
    If check <> 0 Then
        linkCounts = linkCounts + 1
        temp(linkCounts) = allLinks(i)
    End If
Next
On Error GoTo 0
getLinks = temp
End Function
Private子变更链接(addinName作为字符串,wb作为工作簿)
模糊检查只要
我想我会坚持多久
将现有路径设置为字符串
将路径设置为字符串
变光温度
Dim tempA作为变体
Application.DisplayAlerts=False
Application.AskToUpdateLinks=False
Application.ScreenUpdating=False
temp=getLinks(addinName,wb)
出错时继续下一步
correctPath=Application.AddIns(addinName).fullName
对于i=1到100
如果温度(i)=“”,则退出
如果UCase(temp(i))UCase(correctPath),则
wb.ChangeLink温度(i),校正路径,xlLinkTypeExcelLinks
如果结束
下一个
错误转到0
端接头
私有函数getLinks(addinName作为字符串,wb作为工作簿)
Dim allLinks作为变体
模糊检查只要
我想我会坚持多久
变光温度(1至100)作为变型
暗链接与长链接一样重要
检查=0
allLinks=wb.LinkSources
链接计数=0
出错时继续下一步
对于i=LBound(所有链接)到UBound(所有链接)
检查=仪器(1,UCase(所有链接(i)),UCase(附加名称))
如果选择0,则
链接计数=链接计数+1
温度(链接计数)=所有链接(i)
如果结束
下一个
错误转到0
getLinks=temp
端函数
尽管有Application.DisplayAlerts=False和On Error Resume Next等语句,但代码仍挂在我使用.ChangeLink方法的行上。奇怪的是,如果我登录到服务器并手动运行,代码就可以正常工作。我相信这是由于代码试图运行.ChangeLink语句时出现了一些弹出窗口。我看不出这个弹出窗口是什么,因为它在服务器上以不同的登录名运行。所以现在我只是把头撞在墙上

谢谢你的帮助