Reference cell data to update links

ukkz001

Board Regular
Joined
Apr 12, 2005
Messages
199
I have a cell containing the file path and name. I would like to refernce that cell in a macro so that it uses that file info to updates links.

EX. of the cell contiain the file link info:
="'Z:\Department\\ACCTG\Statements\"&TEXT('Daily Rec'!$A$3,"yyyy")&"\"&TEXT('Daily Rec'!$A$3,"mmmm")&"\[Daily Report "&TEXT('Daily Rec'!$A$3,"mm dd.yyyy")&" xls (2).xlsx]Daily Cash Report'!$B$8:$K$500"


Any ideas??

Thanks
 
Last edited:

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Are you saying that your workbook already has links, and that you'd life to change the link source to be whatever that cell results are?

Can you also say whether your workbook has one link source or many?
 
Upvote 0
Yes. The workbook already contains links but the link source changes, the user has to manually change the link source. I would like the macro to automatically change the link source based on the path and file name located in a cell that gets updated.

Thanks,
Kevin
 
Upvote 0
This might work:
Code:
Sub ChangeMyLinks()
    alinks = ThisWorkbook.LinkSources
    ThisWorkbook.ChangeLink Name:=alinks(1), NewName:= _
        Worksheets("my sheet name").Range("A1").Value, Type:=xlExcelLinks
End Sub
.. changing the sheet name and ref to suit.
 
Upvote 0
I received the following error:
"Formula in worksheet contians one or more invalid references"

Here is what I have listed in the refence cell:

="'Z:\Department\ACCTG\Statements\"&TEXT('Daily Rec'!$A$3,"yyyy")&"\"&TEXT('Daily Rec'!$A$3,"mmmm")&"\[Daily Report "&TEXT('Daily Rec'!$A$3,"mm dd.yyyy")&" xls (2).xlsx]Daily Cash Report'!$B$8:$K$500"
 
Upvote 0
If you are just changing source workbook, you don't need to specify sheet and reference.
 
Upvote 0
So the new code would be:

Sub ChangeMyLinks()
alinks = ThisWorkbook.LinkSources
ThisWorkbook.ChangeLink Name:=alinks(1), NewName:= _
Range("F13").Value, Type:=xlExcelLinks
End Sub

Where cell F13 containg the formula to the dynamicly updated link:

="'Z:\Department\ACCTG\Statements\"&TEXT('Daily Rec'!$A$3,"yyyy")&"\"&TEXT('Daily Rec'!$A$3,"mmmm")&"\[Daily Report "&TEXT('Daily Rec'!$A$3,"mm dd.yyyy")&" xls (2).xlsx]Daily Cash Report'!$B$8:$K$500"
 
Upvote 0
Cell F13 formula:

="'Z:\Department\ACCTG\Statements\"&TEXT('Daily Rec'!$A$3,"yyyy")&"\"&TEXT('Daily Rec'!$A$3,"mmmm")&"\Daily Report "&TEXT('Daily Rec'!$A$3,"mm dd.yyyy")&" xls (2).xlsx"
 
Upvote 0
Yeah, that won't work because the last part of the formula:
Daily Cash Report'!$B$8:$K$500" is the linked data that need to be updated.

The first part of the formula is the directory path and Daily Cash Report file name based on the date range found in the "Daily Rec" worksheet. The file is updated daily and the save name by date ex:

Thanks for your help Glenn.
 
Upvote 0

Forum statistics

Threads
1,224,599
Messages
6,179,831
Members
452,946
Latest member
JoseDavid

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