UpdateLinks error?

R

Ray

hello -

I have a very simple (or so I thought) section of code used to update
all external links in a workbook. It seems to update all of the
information but before it finishes, I get the following error message:
Run-time error '1004':
Method 'UpdateLink' of object '_Workbook' failed

Here's my code:
Private Sub UpdateLinks_Click()
Application.DisplayAlerts = False
ActiveWorkbook.UpdateLink Name:=ActiveWorkbook.LinkSources
Application.DisplayAlerts = True

End Sub

Any ideas what would cause the error? And, more importantly, how to
fix it?

TIA,
Ray
 
G

Guest

My guess would be that you have a bad link.


go into Edit=>Links, select each link and click the button to update the
link. See if one fails.
 
M

meatshield

Did your macro update the links and then cause an error message? I
couldn't even run the script without getting an error. I've posted a
sample script that I use to make all of the external links point to
the active workbook. I hope it helps.
Sub LinkToSelf()
Dim Awb As Workbook
Dim aLinks

Application.ScreenUpdating = False
Set Awb = ActiveWorkbook
'Get an array of the external links
aLinks = Awb.LinkSources(xlExcelLinks) 'this will return empty if
there are not external links
'As long as the array is not empty, loop through the array and change
the reference
If Not IsEmpty(aLinks) Then
For I = LBound(aLinks) To UBound(aLinks)
'error catching in case the external link cannot be changed
(if the link references a worksheet
'that exists in the linked workbook, but does not exist in the
active workbook, it will cause an
'error and the link will not be changed
On Error Resume Next
'Point the link back to the active workbook
Awb.ChangeLink Name:=aLinks(I), NewName:=Awb.FullName,
Type:=xlLinkTypeExcelLinks
On Error GoTo 0
Next I
End If
Application.ScreenUpdating = True
Erase aLinks
aLinks = Awb.LinkSources(xlExcelLinks)
If Not IsEmpty(aLinks) Then MsgBox "There are still external links in
this workbook"
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top