Excel Hyperlink mass update

前端 未结 5 1547
离开以前
离开以前 2020-12-30 01:58

I have a spreadsheet with thousands of rows. Each row contains a hyperlink with a path.

The path is not valid, however easily fixable by replacing first part of it w

5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-30 02:51

    Hey cnx.org, way to reinvent the Replace function.

    Sub FindReplaceHLinks(sFind As String, sReplace As String, _
        Optional lStart As Long = 1, Optional lCount As Long = -1)
    
        Dim rCell As Range
        Dim hl As Hyperlink
    
        For Each rCell In ActiveSheet.UsedRange.Cells
            If rCell.Hyperlinks.Count > 0 Then
                For Each hl In rCell.Hyperlinks
                    hl.Address = Replace(hl.Address, sFind, sReplace, lStart, lCount, vbTextCompare)
                Next hl
            End If
        Next rCell
    End Sub
    
    Sub Doit()
    
        FindReplaceHLinks "F:\help\", "F:\SystemHelp\"
    
    End Sub
    

提交回复
热议问题