I have been attempting to write a macro that will remove the hyperlinks in a document and convert the font to the same format as the rest of the document. I've accomplished the first part with this macro:For the second part I recorded my steps using the macro recorder. What I did was do a Replace. I selected ALL, opened the Replace dialogue, searched in the FONT section, for Blue Verdana underlined font, and replaced that with FONT Black TimesNewRoman, no underline. My steps worked perfectly, and the macro recorder recorded my steps, but what it recorded didn't do anything when I tried using the macro (code is below):Sub KillHyperlinksinThisDocument() Dim i As Long For i = ActiveDocument.Hyperlinks.Count To 1 Step -1 ActiveDocument.Hyperlinks(i).Delete Next i End SubThe macro recorder doesn't appear to have captured all the Font detail that's the heart of the replacement. I'd appreciate any help I can get in getting this working.Sub Hypersnew() ' ' Hypersnew Macro ' Macro recorded 1/18/2011 by John. ' Selection.WholeStory Selection.Fields.Unlink Selection.Find.ClearFormatting Selection.Find.Replacement.ClearFormatting With Selection.Find .Text = "" .Replacement.Text = "" .Forward = True .Wrap = wdFindAsk .Format = True .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute Replace:=wdReplaceAll End Sub
Thanks,
John
Last edited by jomili; 01-25-2011 at 08:37 AM.
Something like this
To go through the whole workbookSub Remove_All_Hyperlinks() 'Removes hyperlinks from the active worksheet 'Does not delete the hyperlink text, only the link to the site Do Until ActiveSheet.Hyperlinks.Count = 0 ActiveSheet.Hyperlinks(1).Delete Loop End Sub
Sub Remove_All_Hyperlinks() Dim ws as Worksheet 'Removes hyperlinks from the workbook For Each ws in Thisworkbook.Worksheets 'Does not delete the hyperlink text, only the link to the site Do Until ws.Hyperlinks.Count = 0 ws.Hyperlinks(1).Delete Loop Next ws End Sub
Hope that helps.
RoyUK
--------
If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need
For Excel Tips & Solutions, free examples and tutorials why not check out my downloads
New members please read & follow the Forum Rules
Remember to mark your questions Solved and rate the answer(s)
Roy,
Thanks, but your code does the same function the first macro I posted does, namely delete the hyperlink. However, from one particular website, when I copy and paste to Word, the text is formatted as TimesNewRoman, but the Hyperlinks are formatted as Verdana. So, AFTER running the macro and removing the hyperlinks, the old hyperlink text remains as Blue and Highlighted. That's the problem my second macro in the post is supposed to fix, but doesn't. That's the one I need help with.
Hello jomille
If you examine the styles in your document is there one that relates to the deleted links? If there is, then try setting up a macro to delete all instances of that style.
David
Access and Excel Developer | UK
I can see that there IS a style related to the defunct links, but I'm just starting to use Macros with Excel, so macros in Word are way over my head. I would have no idea on how to use a style in a macro. Can you help?
Perhaps you could start by manually working in Word to remove the style. Then, when you have got as far as understanding styles and applying and removing them you could record a macro to perform the removal.
Search for ‘word styles and formatting’ on the web and you will find out plenty abut them.
David
Access and Excel Developer | UK
Does nobody out on the internet ever delete a specific style? I found tons of hits on deleting unused styles, but nothing for how to delete A style and return everything to Normal. So, I did it this way instead:
The only thing I still want to add I don't know how to even phrase the question, so I've attached an example. There are two little yellow boxy parchemnt scroll things that I believe are Google ads. How would I, with VBA, select and delete those? What are they called?Sub KillHyperlinksinThisDocument() Dim i As Long For i = ActiveDocument.Hyperlinks.Count To 1 Step -1 ActiveDocument.Hyperlinks(i).Delete Next i ActiveDocument.Select With Selection.Font .Name = "Times New Roman" .Size = 12 .Color = wdColorBlack .Underline = False End With
Hello jomili
They are what Word refers to as 'in-line shapes'. Please test this macro as a way of deleting them:
Sub DeleteInlineShapes() ' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Dim rngChar As Range For Each rngChar In ActiveDocument.Characters rngChar.Select If Selection.Type = wdSelectionInlineShape Then Selection.Delete Next rngChar End Sub
David
Access and Excel Developer | UK
Oh, so that's what "in-line shapes" are. I've seen them referred to but had no idea what they were. Your macro worked beautifully. I've added it to what I previously had, so the full macro code now is this:Thanks for all your help on this. This macro is going to be a blessing for me, so thanks for helping me create it.Sub KillHyperlinksinThisDocument() Dim i As Long Dim rngChar As Range 'Part1 - Kill the hyperlinks For i = ActiveDocument.Hyperlinks.Count To 1 Step -1 ActiveDocument.Hyperlinks(i).Delete Next i 'Part2 - set all the fonts to my standard ActiveDocument.Select With Selection.Font .Name = "Times New Roman" .Size = 12 .Color = wdColorBlack .Underline = False End With 'Part3 - get rid of those pesky in-line shapes For Each rngChar In ActiveDocument.Characters rngChar.Select If Selection.Type = wdSelectionInlineShape Then Selection.Delete Next rngChar End Sub
Thanks,
John
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks