links are not updated

A

Alex

I have Sheet1 linked to Sheet2. The Sheet2 is linked to the Sheet3.
I want to update values in the Sheet1 linked to the Sheet2 assuming if any
changes are done in the Sheet3 it'll be reflected in the Sheet1.

So, I'm changing the values in the Sheet3 and closing it. After that, having
Sheet1 opened I'm openning the Sheet2 and everything is fine the values in
the Sheet1 have been updated.

But, when I'm clicking a button on the Sheet1 and using the code below it's
not working - the values in the Sheet1 are not updated when I'm doing changes
in the Sheet3 and closing it and after that openning the Sheet2 through the
code below with supposed to be links updated.

Can anybody help me with it.

Sub Update_Links()
On Error GoTo Update_Links_Err
Dim xlapp As Object
Dim xlbook As Object
Dim strFileName As String
Dim logFlag As Boolean

logFlag = False

strFileName = "Sheet2.xls"

Set xlapp = CreateObject("Excel.Application")

xlapp.DisplayAlerts = False
xlapp.AskToUpdateLinks = False

Set xlbook = xlapp.Workbooks.Open(strFileName, UpdateLinks:=1)
logFlag = True

xlapp.AskToUpdateLinks = True
xlapp.DisplayAlerts = True

xlbook.Close savechanges:=True
xlapp.Quit

Set xlbook = Nothing
Set xlapp = Nothing

Update_Links_exit:

Exit Sub
Update_Links_Err:
xlapp.DisplayAlerts = True
xlapp.AskToUpdateLinks = True
If logFlag Then
xlbook.Close savechanges:=False
xlapp.Quit

Set xlbook = Nothing
Set xlapp = Nothing

End If
MsgBox Err.Description
Resume Update_Links_exit
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