?
Solved

Changing the path to linked excel worksheets programatically

Posted on 2011-03-01
2
Medium Priority
?
228 Views
Last Modified: 2012-05-11
I have a requirement to change the path (name) to a number of linked worksheets by code.
I think it is something to do with the workbook.LinkSources but I am having some problems.

Am I looking at the wrong thing?  What is the property I should be loooking at?  Best of all - does someone have a piece of code to do it and is willing to share it?
0
Comment
Question by:AndyAinscow
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 85

Accepted Solution

by:
Rory Archibald earned 2000 total points
ID: 35006044
For example:
Sub ChangeLinkPaths(strOldPath As String, strNewPath As String)
   Dim arrLinks, I As Long
   arrLinks = ActiveWorkbook.LinkSources(xlExcelLinks)
   If Not IsEmpty(arrLinks) Then
      On Error Resume Next
      Application.DisplayAlerts = False
      For I = LBound(arrLinks) To UBound(arrLinks)
         If InStr(1, arrLinks(I), strOldPath, vbTextCompare) > 0 Then
            ActiveWorkbook.ChangeLink arrLinks(I), Replace$(arrLinks(I), strOldPath, strNewPath), xlLinkTypeExcelLinks
         End If
      Next I
      Application.DisplayAlerts = True
   End If
End Sub

Open in new window


assuming I understood your question correctly.
0
 
LVL 44

Author Comment

by:AndyAinscow
ID: 35006722
Excellent, works like a dream.  Thanks.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
If you need to forecast numbers -- typically for finance -- the Windows and Mac versions of Excel 2016 have a basket of tools to get the job done.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question