Delete Hyperlinks without removing formatting

Pauljj

Well-known Member
Joined
Mar 28, 2004
Messages
2,047
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

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
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,214,591
Messages
6,120,432
Members
448,961
Latest member
nzskater

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
Back
Top