changing links using vba

excelguru123

New Member
Joined
Jun 23, 2021
Messages
2
Office Version
  1. 2013
Platform
  1. Windows
hey folks,

so I have a file that uses 3 different files that need to be updated on a monthly basis. every month, the files get saved into the appropriate month's folder (every month a new folder is created and all new work is saved into that folder). for example
  • for may the folder is named: \\path\\majorfolder\subfolder\may2021\xlfile
  • for june it will be: \\path\\majorfolde\subfolder\june2021\xlfile
to take it a step further: in a single month, several drafts of the 3 linked files are created so they will be as follows:
  • again for may, it will be \\path\\majorfolde\subfolder\may2021\xlfile_draft_1
    • \\path\\majorfolde\subfolder\may2021\xlfile_draft_2
  • similarly for june: \\path\\majorfolde\subfolder\june2021\xlfile_draft_1
    • and so on
each time a new draft is added, the links need to be updated to include the most recent draft of the 3 files. Right now, I use Data->Edit Links to update each file everytime a new draft gets added. I want to be able to automate this so that I can update to the latest draft of each of the 3 links with a single button. I tried to run a macro but when I do it shows the old file path as the previous months file. But it can also be a link of the same month but a different draft. What's the best way to do this?

So far, I used the following code to pull all the links out:

VBA Code:
aLinks = ActiveWorkbook.LinkSources(xlExcelLinks)

If Not IsEmpty(aLinks) Then 
For i = 1 to Ubound(aLinks) 
Cells(i,1).Value = aLinks(i)
Next i 
End If

This pulls out the current links in the file -- I want to then be able to update these to the most recent month and drafts -- how do I go about doing that?

If you're still with me, thanks for reading!!!
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"

Forum statistics

Threads
1,214,985
Messages
6,122,603
Members
449,089
Latest member
Motoracer88

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