Solved

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

Posted on 2013-02-04
5
2,275 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

724 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