I require the VBA code for the user to choose and then change a linked file
I require the VBA code for the user to choose and then change a linked file
Hi, and welcome to the forum.
Try
![]()
Please Login or Register to view this content.
Last edited by Richard Buttrey; 08-10-2013 at 01:52 PM.
Richard Buttrey
RIP - d. 06/10/2022
If any of the responses have helped then please consider rating them by clicking the small star iconbelow the post.
Thanks Richard but not what I require
I am teaching myself VBA and am perhaps not explaining myself clearly
I have a workbook "A" which is linked to Workbook "B"
The user is working in workbook "A" and the code already written requires them to change the link from workbook "B" to one chosen from the same dir
Hi,
In that case, untested but try this slight modification
![]()
Please Login or Register to view this content.
This makes more sense to me but does not work fully
I can see how the code will get the "NewName"
How does the code get linked "CurrentFileName"?
Also does the "NewName" file have to be opened?
I have tried this - the new "NewName" seems work as I have to choose and open
After that the code breaks down - I think it is the "stCurrentFName=ActiveWorkBook.Name" as this should actually refer to the "linked file" and not the "current workbook"
Sorry, I did say it was untested!
Try instead
...assuming there is only one link in operation.![]()
Please Login or Register to view this content.
No, the NewName File does not need to be opened. The instruction GetOpenFileName does as it says on the tin. When the user points to it in the usual windows file dialog box it's assigned to the variable when you click on the 'Open' buttton - which I agree is confusing since it doesn't actually open the file. I suspect MS were just being lazy and used the same FileOpen dialog box as you would use if you do want to open a file.
Still not working
Does the "stCurrentFName" for the link file not also give the path which would then change the last line of code?
I am going to try this again
Hi Richard
I have taken the "Path" out of the code and it now works just as I want it to
Here it is for your (or other users) records
Dim stCurrentFname As String, stNewFName As String, stPathName As String
stCurrentFname = ThisWorkbook.LinkSources(XlLink.xlExcelLinks)(1)
stNewFName = Application.GetOpenFilename
ActiveWorkbook.ChangeLink Name:=stCurrentFname, NewName:=stNewFName
This code changes the "Linked File" to the "New User Chosen File"
You are correct that the code only picks the first "Linked File" - This is fine for me as there is only one Linked File at any one time
However I tried it with two "Linked Files" and when I changed the (1) in "stCurrentFName" to (2) the code picks up the second file
Thanks a lot
You have helped solve the problem I have been battling over for a few weeks now
![]()
Hi Richard
Me again - I am also new to ExcelForum - how do I rate the service I have received?
Thanks again
Hadj
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks