Solved

Changing the path to linked excel worksheets programatically

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
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…
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…

803 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