Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 403
  • Last Modified:

Changelink doe not work

Hi,

I use the code below to change the links with other sheets.

    NewLink = Application.GetOpenFilename("Excel-files,*.xls", 1, "Select File", , False)
    OldLink = ws.Range("B2").Value
    Set ws = ThisWorkbook.Worksheets("Sheet1")
    ThisWorkbook.Changelink Name:=OldLink, NewName:=NewLink, Type:=xlExcelLinks
    Set ws = ThisWorkbook.Worksheets("Sheet2")
    ThisWorkbook.Changelink Name:=OldLink, NewName:=NewLink, Type:=xlExcelLinks

For Sheet1 it works, but not for Sheet2.
What's wrong?

Tx
0
sonmic
Asked:
sonmic
1 Solution
 
jppintoCommented:
Before this line:

OldLink = ws.Range("B2").Value

Do you have ws set already? You're setting Set ws = ThisWorkbook.Worksheets("Sheet1") after this OldLink = ws.Range("B2").Value...

You should do like this:

NewLink = Application.GetOpenFilename("Excel-files,*.xls", 1, "Select File", , False)
Set ws = ThisWorkbook.Worksheets("Sheet1")
OldLink = ws.Range("B2").Value
ThisWorkbook.Changelink Name:=OldLink, NewName:=NewLink, Type:=xlExcelLinks
Set ws = ThisWorkbook.Worksheets("Sheet2")
OldLink = ws.Range("B2").Value
ThisWorkbook.Changelink Name:=OldLink, NewName:=NewLink, Type:=xlExcelLinks

This is how it makes sense to me...

jppinto
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now