change UNC path of multiple hyperlinks

G

Guest

Is there anyway of changing the server name of the UNC path on a hyperlink,
within an excel sheet, after migrating a file server a few excel workbooks
which have multiple hyperlinks in each sheet have not automatically updated
to reflect the new server name.

Can this be changed without having to manually update each link which will
take forever?
 
G

Guest

You should be able to change them with code which shouldn't take forever.

Do it manually one time to a single hyperlink with the macro recorder turned
on to get the basic code.
 
G

Guest

Hi Tom,

Thanks for the quick reply, recording the macro gave me the code of what
happens when 1 cell is changed, for which I can easily change the range for;
however the full hyperlink address is then placed within the marco, which I
do not want. Each link may point to different share's on this new server.

Is it possible to only change the server name that the UNC is relative to
and not the full path?
 
G

Guest

I would try something like this:

Sub ChangeLink()
Dim hlink As Hyperlink
Dim s As String
For Each hlink In ActiveSheet.Hyperlinks
s = hlink.Address
If InStr(1, s, "//Server1", vbTextCompare) Then
s = Replace(s, "//Server1", "//Server2")
hlink.Address = s
End If
Next
End Sub


Test his on a copy of your file.
 
G

Guest

Tom,

Thanks very much for that the code worked (with a slight mod); specifing the
server name with forward slash's ( / ) failed to update the links but simply
changing these to back slash's ( \ ) as per below works at treat...

Sub ChangeLink()
Dim hlink As Hyperlink
Dim s As String
For Each hlink In ActiveSheet.Hyperlinks
s = hlink.Address
If InStr(1, s, "\\Server1", vbTextCompare) Then
s = Replace(s, "\\Server1", "\\Server2")
hlink.Address = s
End If
Next
End Sub

Thaks very much for the quick response, you have saved me a whole load of
hassle.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top