I have the following macro
Sub CheckAndFixLinks(control As IRibbonControl)
'-------------------------------------------------------------------------
' Procedure : CheckAndFixLinks Created by Jan Karel Pieterse
' Purpose : Checks for links to addin and fixes them
' if they are not pointing to proper location
'-------------------------------------------------------------------------
Application.Calculation = xlCalculationManual
Stop
Dim vLink As Variant
Dim vLinks As Variant
'Get all links
vLinks = ActiveWorkbook.LinkSources(xlExcelLinks)
'Check if we have any links, if not, exit
If IsEmpty(vLinks) Then Exit Sub
For Each vLink In vLinks
If vLink Like "*" & "WtsCalc*.xlam" Then
'We've found a link to our add-in, redirect it to
'its current location. Avoid prompts
Application.DisplayAlerts = False
ActiveWorkbook.ChangeLink vLink, ThisWorkbook.Name, xlExcelLinks
Application.DisplayAlerts = True
End If
Next
MsgBox "WtsCalc links re-established"
End Sub
which if I do manually through edit links works fine but when I run it as a macro and F8 through it it gets to "ActiveWorkbook.ChangeLink vLink, ThisWorkbook.Name, xlExcelLinks" and then tries to run through the addins UDFs but with no values and it crashes out.
e.g. one of my UDFs is
Public Function CofM(location As Range, mass As Range) As Variant
Dim dbDivisor As Double
Dim dTemp As Double
Dim n As Long
If Not location.Areas.Count = mass.Areas.Count Then
CofM = CVErr(xlErrRef)
Else
dbDivisor = Application.Sum(mass)
If Not dbDivisor = 0 Then
For n = 1 To location.Areas.Count
dTemp = dTemp + Application.SumProduct(location.Areas(n), mass.Areas(n))
Next n
CofM = dTemp / dbDivisor
Else
CofM = 0
End If
End If
End Function
and it will start stepping through this with the input variables being location = error 2015 & mass = 2023
what is excel trying to do?
If I expand the variables in locals it looks as if excel upon changing the link in the first cell tries to recalculate it however it hasn't yet updated the links in the second cell (which is an input in the first cell) and falls over.
does the link change go through 1 cell at a time and trigger calc manual on each cell change? but then you does this not fall over when using the edit ribbon edit links button (as it is the UDF that is falling over from this)? is there a way to totally disable calculations temporarily to get around this?
Bookmarks