Using Excel 2002/2003 on XP-SP3. Have a spreadsheet with a column (B) of hyperlinks to online documentation (pdf files). I wanted to copy column(B) to D and convert HyperLink Address & TextToDisplay to local pdf file references, and preserve the orginal hyperlinks for future reference.
The code below works fine, except that when it changes the Address on the selected hyperlink (D), the source hyperlink address (B) changes as well. Strangely, the TextToDisplay does not (it works as expected).
Any chance someone can point out what I'm missing?
Sub HyperLinkChange()
Dim path, file As String
Dim h As Hyperlink
Dim x As Integer
Columns("B:B").Select
Selection.Copy
Columns("D:D").Select
ActiveSheet.Paste
Application.CutCopyMode = False
path = "http://www.abc.com/epubs/pdf/"
file = ""
For Each h In ActiveSheet.Columns("D:D").Hyperlinks
x = InStr(1, h.Address, path)
If x > 0 Then
file = Replace(h.Address, path, "")
h.Address = file ' This is the problem - it updates both hyperlinks
h.TextToDisplay = file
End If
Next
End Sub
The code below works fine, except that when it changes the Address on the selected hyperlink (D), the source hyperlink address (B) changes as well. Strangely, the TextToDisplay does not (it works as expected).
Any chance someone can point out what I'm missing?
Sub HyperLinkChange()
Dim path, file As String
Dim h As Hyperlink
Dim x As Integer
Columns("B:B").Select
Selection.Copy
Columns("D:D").Select
ActiveSheet.Paste
Application.CutCopyMode = False
path = "http://www.abc.com/epubs/pdf/"
file = ""
For Each h In ActiveSheet.Columns("D:D").Hyperlinks
x = InStr(1, h.Address, path)
If x > 0 Then
file = Replace(h.Address, path, "")
h.Address = file ' This is the problem - it updates both hyperlinks
h.TextToDisplay = file
End If
Next
End Sub