Last active
March 12, 2019 13:26
-
-
Save supergrass71/1998126c269c6591ef2f853ed4143451 to your computer and use it in GitHub Desktop.
[Remove Hyperlinks] #VBA #Visual Basic
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sub RemoveHlinks() | |
'https://www.extendoffice.com/documents/excel/2221-excel-remove-hyperlink-without-removing-formatting.html | |
'Update 20180220 special sauce from Murray Neish | |
Dim Rng As Range | |
Dim WorkRng As Range | |
Dim TempRng As Range | |
Dim UsedRng As Range | |
Dim xLink As Hyperlink | |
Dim xTitleId As String | |
Application.ScreenUpdating = False | |
On Error Resume Next | |
xTitleId = "KutoolsforExcel, enhanced by Muz" | |
Set WorkRng = Application.Selection | |
Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8) | |
Set UsedRng = Application.ActiveSheet.UsedRange | |
For Each xLink In WorkRng.Hyperlinks | |
Set TempRng = Cells(1, UsedRng.Column + UsedRng.Columns.Count) | |
Set Rng = xLink.Range | |
Rng.Copy TempRng | |
Rng.ClearHyperlinks | |
Set TempRng = TempRng.Resize(Rng.Rows.Count, Rng.Columns.Count) | |
TempRng.Copy | |
Rng.PasteSpecial xlPasteFormats | |
'make it look like a normal cell | |
With Rng.Font | |
.Underline = xlUnderlineStyleNone | |
.ColorIndex = xlAutomatic | |
End With | |
TempRng.Clear | |
Next | |
Application.ScreenUpdating = True | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
as the comments at the top of the file suggest, this one is 98% straight from the extendoffice website. I just added a few lines to improve the formatting once the hyperlinks are removed.