We have an interesting problem here in Excel 2007. I don't know if this problem appears in any other versions, or not.
Essentially I'm using VBA code to update hyperlinks, replacing the \\system-name\share-name with an abstract drive letter. Unfortunately, microsoft is translating the URL and converting the drive letter back into the \\system-name\share-name form.
Do any of you know how I can suppress this automatic replacement?
Here is an abstracted version of the code:
Expand|Select|Wrap|Line Numbers
- Sub Hyperlinks_Find_Replace()
- ''
- '' Macro to find/replace update the hyperlink targets in
- '' the active workbook.
- ''
- ''--string to replace
- Dim sOld As Variant
- sOld = "\\server\ShareName"
- ''--replacement value
- Dim sNew As Variant
- sNew = "P:"
- ''--which workbook?
- Dim book As Excel.Workbook
- Set book = Excel.ActiveWorkbook
- ''--work off each sheet
- Dim sheet As Excel.Worksheet
- For Each sheet In book.Worksheets
- Dim hLink As Excel.Hyperlink
- Dim vOld As String
- Dim vNew As String
- For Each hLink In sheet.Hyperlinks
- vOld = hLink.Address
- vNew = VBA.Replace(vOld, sOld, sNew)
- If vOld <> vNew Then
- hLink.Address = vNew
- End If
- Next hLink
- Next sheet
- End Sub
I can use the same loop and replace the share name with no difficulty.
Thank You,
Oralloy