Solved

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

Posted on 2013-02-04
5
2,078 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

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…
Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

785 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