VBA宏 - 超链接

问题描述:

我想创建一个VBA宏,这将允许我编辑列中的所有选定超链接,并将“文本显示”更改为所有相同的单词。例如,如果这是列:VBA宏 - 超链接

www.google.com/search=cars 
www.google.com/search=houses 
www.google.com/search=cities 

我想突出柱的这三个要素,改变要显示的文字为“谷歌搜索”,这样的结果会是这样:

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

你到底是有什么问题部分用?在这个网站上,你应该展示你到目前为止所尝试的内容,而不仅仅是描述你想要做什么。如果您有任何现有的代码,请用此更新您的问题。 – 2012-07-07 02:27:40

这适用于当前的选择:

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 
+0

感谢DJ,完美的作品! – Emir 2012-07-07 03:00:53