使用string函数更改单元格中的超链接文本
给定一个包含超链接的单元格,我想使用string函数(如Mid)更改显示的文本,但仍保持超链接的地址和function。 我能做什么? 谢谢。
例子:
例1:
细胞包含这个hyperlinke:15玛丽街
需要的输出是这个超链接:玛丽·斯特里 – 如果我点击“玛丽街”就像我点击“15玛丽街”时那样,我想要链接工作。
例2:
我不确定这是否会保持您的链接,或者打破它。 如果它打破了,让我知道。
Sub test() removeLeadingNumbers Range("A1:A10") End Sub Sub removeLeadingNumbers(myRng As Range) Dim cel As Range, chr As String Dim i As Long, k As Long For Each cel In myRng If Not IsEmpty(cel) Then i = Len(cel) For i = 1 To Len(cel) If IsNumeric(cel.Characters(i, 1).Text) Then k = k + 1 Else Exit For End If Next i Debug.Print "remove the first " & k & " letters" cel.Value = Trim(Right(cel.Value, Len(cel.Value) - k)) End If Next cel End Sub
如果要更改显示的文本以删除前面的数字后跟一个空格,请尝试:
Sub DumpTheNumbers() Dim h As Hyperlink, txt As String For Each h In ActiveSheet.Hyperlinks txt = h.TextToDisplay If InStr(txt, " ") <> 0 Then arr = Split(txt, " ") If IsNumeric(arr(0)) Then arr(0) = " " h.TextToDisplay = Trim(Join(arr, " ")) End If End If Next h End Sub