ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   UpdateLinks error? (https://www.excelbanter.com/excel-programming/385135-updatelinks-error.html)

Ray

UpdateLinks error?
 
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


Tom Ogilvy

UpdateLinks error?
 
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.

--
Regards,
Tom Ogilvy

"Ray" wrote:

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



meatshield

UpdateLinks error?
 
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
On Mar 13, 6:38 am, "Ray" wrote:
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





All times are GMT +1. The time now is 02:46 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com