Solved

Changing the path to linked excel worksheets programatically

Posted on 2011-03-01
2
222 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 500 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

Independent Software Vendors: 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

Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
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…

734 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