I need to change a lot of hyperlinks in a spreadsheet, as users where saving to their shared drive instead of a central location.
I have this code, which is nearly working...
Public Sub ChangeHyperlinks()
Dim ws As Worksheet
Dim hlink As Hyperlink
Dim p As Long
For Each ws In ActiveWorkbook.Worksheets
For Each hlink In ws.Hyperlinks
p = InStrRev(hlink.Address, "\\fileserver\profiles\LMM\Desktop")
If p > 0 Then
hlink.Address = "\\fileserver\documents\link files" & Mid(hlink.Address, p + 1)
End If
Next
Next
End Sub
However, what is happening when I run it, it's putting the new path in, then adding the old path afterwards, I want the old path removed and just the filename adding to the new. Is that easy to do?
I have this code, which is nearly working...
Public Sub ChangeHyperlinks()
Dim ws As Worksheet
Dim hlink As Hyperlink
Dim p As Long
For Each ws In ActiveWorkbook.Worksheets
For Each hlink In ws.Hyperlinks
p = InStrRev(hlink.Address, "\\fileserver\profiles\LMM\Desktop")
If p > 0 Then
hlink.Address = "\\fileserver\documents\link files" & Mid(hlink.Address, p + 1)
End If
Next
Next
End Sub
However, what is happening when I run it, it's putting the new path in, then adding the old path afterwards, I want the old path removed and just the filename adding to the new. Is that easy to do?