【问题标题】:Search and Replace Certain Extensions in Hyperlinks in Excel在 Excel 中搜索和替换超链接中的某些扩展名
【发布时间】:2015-06-20 02:10:52
【问题描述】:

我有一个带有大量超链接的 excel 文件。一些超链接匹配某种模式,比如说file:///\\location\file_name_<xxx>.pdf,其中<xxx> 会有所不同。还有其他类似的超链接,比如file:///\\location\other_file_<xxx>.pdf

我希望能够搜索和替换所有匹配的超链接(使用简单的 * 通配符进行解释)*file_name*.pdf 并替换为*file_name*.mht

因此,任何指向与 file_name_<xxx> 匹配的 PDF 的超链接都将其扩展名替换为 mht

【问题讨论】:

    标签: regex excel hyperlink


    【解决方案1】:

    您可以使用开发人员选项卡下的 Visual Basic 来使用正则表达式。你必须做很多编码。我会提供我自己的解释,但是这个问题的答案已经在另一个 stackoverflow 问题中得到了相当彻底的解释。点击这里>>(How to use Regular Expressions (Regex) in Microsoft Excel both in-cell and loops)

    总结:

    第 1 步:将 VBA 引用添加到“Microsoft VBScript 正则表达式 5.5”

    第 2 步:定义您的模式

    第 3 步:作为宏运行、作为单元内函数运行或循环遍历范围

    我相信对您最有帮助的示例是示例 4:

    Private Sub splitUpRegexPattern()
    Dim regEx As New RegExp
    Dim strPattern As String
    Dim strInput As String
    Dim strReplace As String
    Dim Myrange As Range
    
    Set Myrange = ActiveSheet.Range("A1:A3")
    
    For Each C In Myrange
        strPattern = "(^[0-9]{3})([a-zA-Z])([0-9]{4})"
    
        If strPattern <> "" Then
            strInput = C.Value
            strReplace = "$1"
    
            With regEx
                .Global = True
                .MultiLine = True
                .IgnoreCase = False
                .Pattern = strPattern
            End With
    
            If regEx.test(strInput) Then
                C.Offset(0, 1) = regEx.Replace(strInput, "$1")
                C.Offset(0, 2) = regEx.Replace(strInput, "$2")
                C.Offset(0, 3) = regEx.Replace(strInput, "$3")
            Else
                C.Offset(0, 1) = "(Not matched)"
            End If
        End If
    Next
    End Sub
    

    【讨论】:

    • 太棒了,多亏了这个和链接,我解决了我的问题。非常感谢
    • 没问题,很高兴你知道了!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-12
    • 2012-06-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多