Solved

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

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

726 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