我想创建一个VBA宏,它允许我编辑列中所有选定的超链接并更改"文本以显示"对所有人说同一个词。例如,如果这是列:
www.google.com/search=cars
www.google.com/search=houses
www.google.com/search=cities
我想突出显示该列的这三个元素,并将文本更改为显示到" Google搜索"结果就是这样:
Google Search
Google Search
Google Search
编辑:所以我发现了一个类似于我想在微软support site上做的宏,但我的问题是这个宏针对表格中的所有超链接而我想要选择一个用于编辑超链接的特定列。
Sub HyperLinkChange()
Dim oldtext As String
Dim newtext As String
Dim h As Hyperlink
oldtext = "http://www.microsoft.com/"
newtext = "http://www.msn.com/"
For Each h In ActiveSheet.Hyperlinks
x = InStr(1, h.Address, oldtext)
If x > 0 Then
If h.TextToDisplay = h.Address Then
h.TextToDisplay = newtext
End If
h.Address = Application.WorksheetFunction. _
Substitute(h.Address, oldtext, newtext)
End If
Next End Sub
答案 0 :(得分:1)
这适用于当前选择:
Sub SetLinkText()
Dim LinkText As String
Dim h As Hyperlink
LinkText = InputBox("Enter link text")
If LinkText = "" Then Exit Sub
For Each h In Selection.Hyperlinks
h.TextToDisplay = LinkText
Next
End Sub