VBA to change links to external workbooks

Jose_Chasez

Board Regular
Joined
May 25, 2009
Messages
117
I have one workbook ("Master") that I am using to create a handful of new workbooks ("Templates"). When creating the new workbooks, there are a couple of worksheets that I copy from the "Master" file to the new files, as they contain data that is needed in the new files.
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:p></o:p>
For example, I have a sheet called "Project Master List" that is copied from the master file and inserted into each template. Within the template, I have formulas that refer back to this "Project Master List" worksheet. My issue is that, within the newly-created workbooks, these formulas are referring to the "Project Master List" worksheet from the "Master" file, rather than the one in the newly-created workbook.
<o:p></o:p>
In other words, within the new workbooks, if I click on the formula bar for a given formula, I see:

Code:
='[Master File.xls]Project Master List'!$A$1

, instead of simply

Code:
='Project Master List'!$A$1
<o:p></o:p>
<o:p></o:p>
My question is how to remove these external links, and make my new files "self-contained". One additional wrinkle is that the name of the master workbook changes from time-to-time, so I'd prefer not to hardcode its name in the macro.
<o:p></o:p>
Thanks.
 
Last edited:

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Anyone? Not sure if I've clearly explained my issue above. Let me know if any additional information is needed to troubleshoot this.

Thanks again!
 
Upvote 0
Hi Jose

Record a macro of yourself editing links>Change Source>Masterfile to the current file (ie refer back to itself).

This should give you the code you need.
 
Upvote 0
Thanks for the tip. The macro recorder was helpful. I only needed to tweak the code, so that it didn't refer to hard-coded file names and paths.

In case it helps anyone else, my final code is below.

  • Folder_name is a string variable for the folder that the master file is saved in
  • Source_WB is a variable for the "master" workbook that creates the new files
  • Target_WB_Filename is a variable for the name of the new workbook being created by the macro
Code:
    ActiveWorkbook.ChangeLink Name:= _
            Folder_Name & Source_WB.Name, NewName:= _
            Target_WB_Filename, Type:=xlExcelLinks
 
Upvote 0

Forum statistics

Threads
1,214,825
Messages
6,121,787
Members
449,049
Latest member
greyangel23

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top