Avatar of ansonindustries
ansonindustries
Flag for United States of America asked on

Excel Change All Hyperlinks

I have the following code however it does not change the hyper link

Sub changeHYperlinks()
Dim hyp As Hyperlink
Dim sh As Worksheet
For Each sh In ActiveWorkbook.Sheets
    For Each hyp In sh.Hyperlinks
        hyp.Address = Replace(hyp.Address, "file:///C:\Documents and Settings\hsmith\Application Data\Microsoft\Excel", "file:///\\corp-win\DATA\Legal")
        hyp.TextToDisplay = Replace(hyp.TextToDisplay, "file:///C:\Documents and Settings\hsmith\Application Data\Microsoft\Excel", "file:///\\corp-win\DATA\Legal")
    Next hyp
Next sh
End Sub

I have tried it without the "file:///" but still no luck.  Attached is a copy of my work.  Please try to make it work.

If you hover of the link it states "file:///C:\Documents and Settings\hsmith\Application Data\Microsoft\Excel"

however if you right click it and choose edit link this is what i see and i have tired this path as well.

..\..\hsmith\Application%20Data\Microsoft\Excel\Contract%20Reviews\Chicago\Alps%20Construction%20Master%20Contract.pdf

Contract-Review-Tracker-EE.xlsm
Microsoft Excel

Avatar of undefined
Last Comment
Tommy Kinard

8/22/2022 - Mon
redmondb

Hi, ansonindustries.

Drop all occurrences of "file:///".

Regards,
Brian.
ansonindustries

ASKER
I did that and still no luck.
redmondb

ansonindustries,

It worked for me. To be sure, to be sure, Please try this...
Sub changeHYperlinks()
Dim hyp As Hyperlink
Dim sh As Worksheet
For Each sh In ActiveWorkbook.Sheets
    For Each hyp In sh.Hyperlinks
        hyp.Address = Replace(hyp.Address, "C:\Documents and Settings\hsmith\Application Data\Microsoft\Excel", "\\corp-win\DATA\Legal")
        hyp.TextToDisplay = Replace(hyp.TextToDisplay, "C:\Documents and Settings\hsmith\Application Data\Microsoft\Excel", "\\corp-win\DATA\Legal")
    Next hyp
Next sh
End Sub

Open in new window

Thanks,
Brian.  
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
ansonindustries

ASKER
I dont know what to tell you its not working for me.  can you send me your copy?
ASKER CERTIFIED SOLUTION
Tommy Kinard

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
HainKurt

use

        hyp.Address = Replace(hyp.Address, "../../hsmith/Application Data/Microsoft/Excel/Contract Reviews/Atlanta/", "file:///\\corp-win\DATA\Legal\")
ansonindustries

ASKER
thanks.  i dont know why it wont work for me.  ill worry about it later.  thanks again though.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
HainKurt

also maybe you need to put the same thing into TextToDisplay

        hyp.Address = Replace(hyp.Address, "../../hsmith/Application Data/Microsoft/Excel/Contract Reviews/Atlanta/", "file:///\\corp-win\DATA\Legal\")
        hyp.TextToDisplay = hyp.Address
Tommy Kinard

Thanks for the points and the grade.