Replace part of hyperlink

后端 未结 2 486
粉色の甜心
粉色の甜心 2021-01-14 17:42

I need to modify a lot of hyperlinks in an .xls workbook. My links are like this:

\\\\\\mysrv001\\some\\path\\documents.doc and I need to replace

相关标签:
2条回答
  • 2021-01-14 18:08

    Whoops! You're extracting and keeping the left part of your path string, where what you really want to do is to discard it!

    EDIT: Also, you can't use string functions (Left, Right, Len...) on a Hyperlink object like that. This is what is causing the error. You have to extract the Hyperlink object's Address property -- that's a string.

    Replace

    path = Left(hLink, 11) ' throws error: Object doesn't support this property...
    

    with

    path = Mid(hLink.Address, 12) ' returns "some\path\documents.doc"
    ' or, equivalently:
    'path = Right(hLink.Address, Len(hLink.Address) - 11) 
    
    0 讨论(0)
  • 2021-01-14 18:22

    try this

    Sub test()
        Dim hLink As Hyperlink
        Dim wSheet As Worksheet
    
        For Each wSheet In Worksheets
           For Each hLink In wSheet.Hyperlinks
                hLink.Address = Replace(hLink.Address, "\\mysrv001\", "\\mysrv002\")
            Next hLink
        Next
    End Sub
    
    0 讨论(0)
提交回复
热议问题