Converting Hyperlinks to function based hyperlinks

Erimikos

New Member
Joined
May 6, 2016
Messages
1
I was hoping I could get some assistance here.

As a heads-up, I am terrible at VB, and have never even looked at Excel macro's before today.

I have a user who uses a large spreadsheet with links to documents all over my organizations share drive. Periodically, he will leave the system up overnight with the sheet open, and after patches are installed, the system will convert all the links to instead of searching the UNC path looking in c:\users\%username%\AppData\Roaming\.... where the links do not exist. I understand this is Microsoft trying to maintain the links through offline files, but not an option here.

I use shadow copies to pull a backup of the file, but all the links now point to folders within the shadow copy, instead of current data.

With a bunch of google searching I have been able to create a macro to fix that problem for all the links and change the text to the correct address.

However, what I am now trying to do is prevent this from happening in the first place by converting the cells to formula based links.

ie.. change a cell with a text field of 'IA0087' and a URL of \\Server\Share\TMB\Bldg Folders\IA0087 TMB-"
to instead contain
=HYPERLINK("\\Server\Share\TMB\TMB Bldg Folders\IA0087 TMB-", "IA0087")

I understand this should prevent Excel from automatically updating the cell...

I have figured out that I can use this to enter the formula into a cell:
ActiveCell.FormulaR1C1 = "=HYPERLINK(""\\Server\Share\TMB\TMB Bldg Folders\IA0087 TMB-"", ""IA0087"")"

But I am not sure how to create a loop that will go through all the cells on a sheet, or even a selection at a time, and convert the current hlink.address to text filling the target portion of the formula, and then to convert the current hlink.TextToDisplay to the friendly name in the hyperlink field..

Complicating things further, not all of the folders have the same string after the building number..

All are under \\Server\Share\TMB\TMB Bldg Folders\, but some have "TMB-", some have, "TMB", some have "TMB None on File"

So.. to make a long story short, HALP!

If anyone could point me in the right direction or give me some tips I would be extremely grateful.

If anyone was interested, or curious, the script I used from a web-page and modified in order to fix the problem of the links pointing to previous version was

Sub FixLinks()

Dim intStart As Integer
Dim intEnd As Integer
Dim strCol As String
Dim hLink As Hyperlink

intStart = 3
intEnd = 400

For i = intStart To intEnd

For Each hLink In ActiveSheet.Hyperlinks
'hLink.TextToDisplay = Replace(hLink.TextToDisplay, "Share\@GMT-2016.05.05-12.06.14\TMB\", "Share\TMB\")
hLink.Address = Replace(hLink.Address, "Share\@GMT-2016.05.05-12.06.14\TMB\", "Share\TMB\")
Next hLink

Next i

End Sub
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.

Forum statistics

Threads
1,215,345
Messages
6,124,408
Members
449,157
Latest member
mytux

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