Solved

Changing the path to linked excel worksheets programatically

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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

743 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now