![]() |
#1
|
|||
|
|||
![]()
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 Alex |
#2
|
|||
|
|||
![]()
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 |
#3
|
|||
|
|||
![]() Quote:
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 |
#4
|
|||
|
|||
![]()
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 |
#5
|
|||
|
|||
![]()
Wonderful piece of code, thank you very much!
Alex |
#6
|
|||
|
|||
![]()
I tried running this, and it's worth clarifying that this removes all hyperlinks that happen to span a paragraph break. It removes the entire hyperlink, not just from the paragraph break. Personally I just need it removed from the paragraph break, so it did not solve my version of the problem.
It's also worth noting that the solution relies on the hyperlink having a specific character style. This might not always be the case, and the name of the default style varies with language settings. This is a potential problem for more wide-spread use. |
#7
|
|||
|
|||
![]()
I need to remove the hyperlinks from paragraph marks (as this causes us some issues).
Sometimes a hyperlink at the end of a paragraph might extend to include the paragraph mark, but it could also be that a single hyperlink is applied across multiple paragraphs (rare, but the code needs to account for this). I can't really code, so have attempted to use Copilot for this (with manual troubleshooting), but after a lot of trial-and-error, I keep running into the same issues. This is the current version: Code:
Sub ReapplyHyperlinksWithoutRemovingText1() Dim doc As Document Dim hl As hyperlink Dim hlRange As Range Dim hlText As String Dim startPos As Long Dim endPos As Long Dim i As Long Dim hlAddress As String Dim hlSubAddress As String Dim partRange As Range Set doc = ActiveDocument ' Loop through each hyperlink in the document For Each hl In doc.Hyperlinks Set hlRange = hl.Range hlText = hlRange.Text startPos = hlRange.Start endPos = hlRange.End hlAddress = hl.Address hlSubAddress = hl.SubAddress ' Check if the hyperlink text contains a paragraph break If InStr(hlText, vbCr) > 0 Or InStr(hlText, vbLf) > 0 Then ' Remove the hyperlink hl.Delete ' Split the text by paragraph breaks Dim parts() As String parts = Split(hlText, vbCr) ' Reapply hyperlink to the first part only If parts(0) <> "" Then Set partRange = doc.Range(startPos, startPos + Len(parts(0))) partRange.Hyperlinks.Add _ Anchor:=partRange, _ Address:=hlAddress, _ SubAddress:=hlSubAddress, _ TextToDisplay:=parts(0) End If End If Next hl End Sub Next, this code only handles this in the body text of the document, but I need it to also do this for footnotes. This I was also unable to get working. It was essentially the exact code, but wrapped inside "For Each footnote In doc.Footnotes; For Each hl In footnote.Range.Hyperlinks" - and it did find and remove the hyperlink in a footnote, but it then reapplied the hyperlink to the first link in the body text and not the footnote. No idea why. Anyone able to help with at least getting this to run on footnots? It would be super helpful! |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
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 |
![]() |
leonardevens | Word | 1 | 07-13-2015 12:14 PM |
Finding Paragraph Marks | BZee | Word | 4 | 02-14-2015 02:12 PM |
![]() |
Cara | Word | 2 | 04-07-2011 10:26 AM |