Hello all - longtime lurker, first post! I have five different Excel "source" files with different structures, locations of data, that create financial projections for different products. The five source files I want to combine information from the five source files into a single "consolidated" Excel file using external links. I then want users to be able to update the links via Macro, so that when they need to update, all they get is a "file open" dialog that they can use to navigate to the new source file or files. Essentially I am using a macro to replace the "Data", "Edit Links", "Change Source" then select the link and navigate to the new source file or files. I cannot combine the five source files into one, they are used by different audiences with different levels of knowledge, not a feasible approach at this point.
Using information from this site, the macro below works when there's only one External Link source, but if I have multiple sources, it attempts to update all of the external links from the five different source files with a single new source file, which doesn't work. The premise of the macro was to go to a cell with a link to one of the five source files (the named range "CentPharm") then change the link name by having the user navigate to a directory and file, click the name and it updates. The premise was that when updating the link manually (via Data, Edit Links) every link to the source file is updated if ANY link is updated. The manual way works fine if there's more than one source file, but the macro tries to update every link to all of the different source files with the name chosen from the dialog.
Sub UpdateCentralPharmacy()
Dim varNewLink As Variant
Dim lnk As Variant
Application.Goto Reference:="CentPharm"
' get all links
lnk = ActiveWorkbook.LinkSources(xlExcelLinks)
If Not IsEmpty(lnk) Then
' prompt for the new file for the link
varNewLink = Application.GetOpenFilename("Excel Files (*.xls*), *.xls*")
' if user didn't cancel, refresh the link
If varNewLink <> False Then
ActiveWorkbook.ChangeLink Name:=lnk(1), NewName:=varNewLink, _
Type:=xlExcelLinks
End If
End If
End Sub
I don't want to "loop" all five source files, which doesn't seem possible anyway. My plan was to have five unique macro that would update each of the five corresponding source files when they're run, so that if a user only needed to update the external links for source files 1 and 4, they'd run Macro 1 and Macro 4.
Thanks in advance for any thoughts anyone can share!
Using information from this site, the macro below works when there's only one External Link source, but if I have multiple sources, it attempts to update all of the external links from the five different source files with a single new source file, which doesn't work. The premise of the macro was to go to a cell with a link to one of the five source files (the named range "CentPharm") then change the link name by having the user navigate to a directory and file, click the name and it updates. The premise was that when updating the link manually (via Data, Edit Links) every link to the source file is updated if ANY link is updated. The manual way works fine if there's more than one source file, but the macro tries to update every link to all of the different source files with the name chosen from the dialog.
Sub UpdateCentralPharmacy()
Dim varNewLink As Variant
Dim lnk As Variant
Application.Goto Reference:="CentPharm"
' get all links
lnk = ActiveWorkbook.LinkSources(xlExcelLinks)
If Not IsEmpty(lnk) Then
' prompt for the new file for the link
varNewLink = Application.GetOpenFilename("Excel Files (*.xls*), *.xls*")
' if user didn't cancel, refresh the link
If varNewLink <> False Then
ActiveWorkbook.ChangeLink Name:=lnk(1), NewName:=varNewLink, _
Type:=xlExcelLinks
End If
End If
End Sub
I don't want to "loop" all five source files, which doesn't seem possible anyway. My plan was to have five unique macro that would update each of the five corresponding source files when they're run, so that if a user only needed to update the external links for source files 1 and 4, they'd run Macro 1 and Macro 4.
Thanks in advance for any thoughts anyone can share!