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
ansonindustriesAsked:
Who is Participating?
 
Tommy KinardCommented:
I removed the file:/// but I also change the replace function a little please see attached. Contract-Review-Tracker-EE.xlsm
0
 
redmondbCommented:
Hi, ansonindustries.

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

Regards,
Brian.
0
 
ansonindustriesAuthor Commented:
I did that and still no luck.
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

 
redmondbCommented:
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.  
0
 
ansonindustriesAuthor Commented:
I dont know what to tell you its not working for me.  can you send me your copy?
0
 
HainKurtSr. System AnalystCommented:
use

        hyp.Address = Replace(hyp.Address, "../../hsmith/Application Data/Microsoft/Excel/Contract Reviews/Atlanta/", "file:///\\corp-win\DATA\Legal\")
0
 
ansonindustriesAuthor Commented:
thanks.  i dont know why it wont work for me.  ill worry about it later.  thanks again though.
0
 
HainKurtSr. System AnalystCommented:
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
0
 
Tommy KinardCommented:
Thanks for the points and the grade.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.