Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 12-30-2020, 10:44 AM
alex100 alex100 is offline Remove the hyperlinks on paragraph marks Windows 7 64bit Remove the hyperlinks on paragraph marks Office 2016
Advanced Beginner
Remove the hyperlinks on paragraph marks
 
Join Date: May 2020
Posts: 79
alex100 is on a distinguished road
Default Remove the hyperlinks on paragraph marks

How can I remove the hyperlinks on paragraph marks, please?

What I have so far is this code...

Code:
Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles("Hyperlink")
Selection.Find.Replacement.ClearFormatting
With Selection.Find
    .Text = "^p"
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindContinue
    .Format = True
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    .Execute Replace:=wdReplaceAll
 End With
The problem is that it will remove both the hyperlink and the paragraph. What I need is to preserve the paragraph and remove only the hyperlink.



Alex
Reply With Quote
  #2  
Old 12-30-2020, 01:52 PM
gmaxey gmaxey is offline Remove the hyperlinks on paragraph marks Windows 10 Remove the hyperlinks on paragraph marks Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,422
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

Hyperlink is a character style so I don't really know why you would have applied it to the paragraph marks in the first place:

Code:
Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey
Dim oRng As Range
  Selection.Find.ClearFormatting
  Selection.Find.Replacement.ClearFormatting
  Set oRng = ActiveDocument.Range
  With oRng.Find
    .Text = "^p"
    .Style = "Hyperlink"
    While .Execute
      oRng.Select
      Selection.ClearCharacterAllFormatting
      oRng.Collapse wdCollapseEnd
    Wend
 End With
lbl_Exit:
  Exit Sub
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #3  
Old 12-31-2020, 01:23 AM
alex100 alex100 is offline Remove the hyperlinks on paragraph marks Windows 7 64bit Remove the hyperlinks on paragraph marks Office 2016
Advanced Beginner
Remove the hyperlinks on paragraph marks
 
Join Date: May 2020
Posts: 79
alex100 is on a distinguished road
Default

Quote:
Originally Posted by gmaxey View Post
Hyperlink is a character style so I don't really know why you would have applied it to the paragraph marks in the first place
They can sometimes be found after pasting web content into Word. So, I'm not the one applying them... :-)

In regards to your script... i hope I'm not missing something, but it doesn't seem to work. It does match all the hyperlinked paragraphs, but the links are still there after processing.

Alex
Reply With Quote
  #4  
Old 12-31-2020, 07:51 AM
gmaxey gmaxey is offline Remove the hyperlinks on paragraph marks Windows 10 Remove the hyperlinks on paragraph marks Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,422
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

Sorry. I thought you were just trying to eliminate the hyperlink character style from the paragraph marks. To actually remove all hyperlinks contained in such paragraphs you could revise as:

Code:
Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey
Dim oRng As Range
Dim lngHL As Long
  Selection.Find.ClearFormatting
  Selection.Find.Replacement.ClearFormatting
  Set oRng = ActiveDocument.Range
  With oRng.Find
    .Text = "^p"
    .Style = "Hyperlink"
    While .Execute
      oRng.Select
      Selection.ClearCharacterAllFormatting
      For lngHL = oRng.Paragraphs(1).Range.Hyperlinks.Count To 1 Step -1
        oRng.Paragraphs(1).Range.Hyperlinks(lngHL).Delete
      Next lngHL
      oRng.Collapse wdCollapseEnd
    Wend
 End With
lbl_Exit:
  Exit Sub
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #5  
Old 12-31-2020, 09:00 AM
alex100 alex100 is offline Remove the hyperlinks on paragraph marks Windows 7 64bit Remove the hyperlinks on paragraph marks Office 2016
Advanced Beginner
Remove the hyperlinks on paragraph marks
 
Join Date: May 2020
Posts: 79
alex100 is on a distinguished road
Default

Wonderful piece of code, thank you very much!

Alex
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Remove the hyperlinks on paragraph marks Remove paragraph marks in Excel from Word-sourced text Peterson Excel 6 08-18-2020 11:36 PM
Help me, remove the marks occur at begin and last paragraph ngocanhwdn Word 6 06-25-2019 07:57 AM
Remove the hyperlinks on paragraph marks Paragraph marks appear suddently leonardevens Word 1 07-13-2015 12:14 PM
Finding Paragraph Marks BZee Word 4 02-14-2015 02:12 PM
Remove the hyperlinks on paragraph marks Hide paragraph format marks Cara Word 2 04-07-2011 10:26 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:49 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft