Link between two files with changing file name

scir2008

New Member
Joined
Nov 13, 2008
Messages
1
I have two excel files that I am linking, where one file always keeps the same file name (File 1.xls) and another file that is opened as read only and then saved as a different name (File2.xls).

So File1.xls is from a supplier and is consistently updated and calculates certain results, File2.xls is a template for quoting where customer specific information is entered, and calculated results from File1.xls are displayed.

File2.xls is then used a 'Save As...' and the file name is changed. What I'm trying to do is write a macro to re-link File1.xls and the new NewName2.xls file. Here's what I have so far:

Sub Macro1()

Windows("File1.xls").Activate
Application.Run "File1.xls!UnProtectInputsSheet"
ChDir "C:\Customer Files\"
ActiveWorkbook.ChangeLink Name:="File2.xls" _
, NewName:="FileToOpen = Application.GetOpenFilename _", Type:=xlExcelLinks
End Sub

So an open file dialog opens, the new renamed file is selected, but the new source file becomes "FileToOpen = Application.GetOpenFilename _" and any changes that made after that are not reflected in File1.xls. Obviously I'm a newb at this, but I'm trying to figure out to have an FileToOpen function work with a dynamic filename change. Any suggestions would be greatly appreciated and GLAD I found such a great message board!
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Not sure if you've gotten an answer to this, but here is your solution...change your code to:

Sub Macro1()

Windows("File1.xls").Activate
Application.Run "File1.xls!UnProtectInputsSheet"
ChDir "C:\Customer Files\"
ActiveWorkbook.ChangeLink Name:="File2.xls" _
, NewName:=Application.GetOpenFilename, Type:=xlExcelLinks
End Sub
 
Upvote 0

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,399
Latest member
alchavar

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