Delete Hyperlinks without removing formatting

Pauljj

Well-known Member
Joined
Mar 28, 2004
Messages
2,046
If I use the following code to delete hyperlinks it also removes the formatting, can the code be changed to only remove the link and nothing else ?

For Each ws in ThisWorkbook.Worksheets
ws.Hyperlinks.Delete
Next ws
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.

erik.van.geit

MrExcel MVP
Joined
Feb 1, 2003
Messages
17,832
Hi,

You will need to loop through the hyperlinks and handle their "parents". If the parent is not a range (could be an object, picture, ...), the code must skip to the next one.

try this
Code:
Option Explicit

Sub remove_hyperlinks_keep_font()
'Erik Van Geit
'070809

Dim ws As Worksheet
Dim h As Hyperlink
Dim a As String

On Error Resume Next
    For Each ws In ThisWorkbook.Worksheets
        For Each h In ws.Hyperlinks
            With h.Parent
            a = .Address
                If Err Then
                Err.Clear
                Else
                'more code could retrieve the font before deleting the hyperlink
                'this code assumes standard settings are applied
                h.Delete
                .Font.ColorIndex = 5
                .Font.Underline = xlUnderlineStyleSingle
                End If
            End With
        Next h
    Next ws

End Sub

kind regards,
Erik
 
Upvote 0

Forum statistics

Threads
1,191,191
Messages
5,985,215
Members
439,947
Latest member
fabiannic

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top