I have some cells in a worksheet that contain Inserted hyperlinks. I want to remove the hyperlinks and leave the "friendly name" in the cell. I can do this with:
Sub dural()
Dim h As Hyperlink
For Each h In ActiveSheet.Hyperlinks
h.Delete
Next h
End Sub
This little Sub works. However if I start with:
and run the macro, I get:
The format of the cell has been ruined! Is there anyway to remove the hyperlink and leave the formatting alone??
EDIT#1:
examining hyperlink properties, I got this to work:
Sub dural2()
Dim h As Hyperlink, addy As String, z As String
For Each h In ActiveSheet.Hyperlinks
addy = h.Range.Address
z = h.Parent
Range(addy).ClearContents
Range(addy).Value = z
Next h
End Sub
The Hyperlink object has certain properties which, through trial and error I established that, for a simple hyperlink to another cell on the same sheet:
As .SubAddress contains:
the location within the document associated with the hyperlink
I changed your code to:
Sub dural()
Dim h As Hyperlink
For Each h In ActiveSheet.Hyperlinks
h.SubAddress = ""
Next h
End Sub
and found that the hyperlink no longer works but your cell formatting is preserved.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.