Solved

Change hyperlink 'text to display' to match 'hyperlink adress' using VBA

Posted on 2013-02-04
5
2,046 Views
Last Modified: 2013-02-05
Dear Experts:

I got hundreds of hyperlinks on the active worksheet.

I would like to change all hyperlinks' property 'Text to display' to exactly match the property 'Hyperlink address' using VBA.

Help is much appreciated. Thank you very much in advance.

Regards, Andreas
0
Comment
Question by:AndreasHermle
5 Comments
 
LVL 7

Assisted Solution

by:Beneford
Beneford earned 200 total points
ID: 38850214
This'll do it.  (And you could add some code to strip off the http:// or mailto: at the beginning of each URL if you don't want them included).

Sub FixHyperlinks()

'  Replace all text showing behind hyperlinks with the hyperlink itself

    Dim aSheet As Worksheet
    Dim aCell As Range
'
    For Each aSheet In Sheets
        For Each aCell In aSheet.UsedRange.Cells
            If aCell.Hyperlinks.Count > 0 Then
               aCell = aCell.Hyperlinks.Item(1).Address
            End If
        Next
    Next
    

Open in new window

0
 
LVL 13

Assisted Solution

by:stergium
stergium earned 100 total points
ID: 38850219
Hello
You need something like this ?

Sub HyperLinkChange()
   Dim oldtext As String
   Dim newtext As String
   Dim h As Hyperlink
       oldtext = "previous value"
       newtext = "Text to display"

' Check all hyperlinks on active sheet.
       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

hope that helps
0
 
LVL 16

Accepted Solution

by:
terencino earned 200 total points
ID: 38850547
In short..
Sub FixLinks()
For Each hyp In ActiveSheet.Hyperlinks
    hyp.TextToDisplay = hyp.Address
Next hyp
End Sub

Open in new window

...Terry
0
 

Author Comment

by:AndreasHermle
ID: 38852870
Dear all,

thank you very much  for your overwhelming support. I will test it tomorrow and then get back to you.  

Again, thank you very much.

Regards, Andreas
0
 

Author Closing Comment

by:AndreasHermle
ID: 38858413
Dear all,

thank you very much for your overwhelming support. All of the codes work just fine. Terencino's one is the most concise therefore the most points go to him.

Again, thank you very much for your professional and valuable help.

Regards, Andreas
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Drop Down List with Unique/Distinct Values (Part II - ComboBox or ListBox and Data Validation List Bonus!) David Miller (dlmille) Intro This article focuses on delivering unique, sorted lists to list objects (e.g., ComboBox, ListBox) and Dat…
Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
Viewers will learn the basics of slicers and timelines for both PivotTables and standard Excel tables in Excel 2013.
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now