View Single Post
 
Old 01-31-2020, 08:54 AM
noslenwerd noslenwerd is offline Windows 10 Office 2016 for Mac
Novice
 
Join Date: Dec 2019
Posts: 15
noslenwerd is on a distinguished road
Default

macropod... thank you again for your help thus far.

The code you helped with, which is below, strips out the bolded URL in the link format in my WordDoc.

For instance it starts as this:
<a href="https://developers.google.com/speed/pagespeed/insights/?url=websiteurl.com">PageSpeed Insights</a>
And ends up linking to this (strips everything after the =):
PageSpeed Insights

Code:
Sub ConvertLinks()
Dim StrAddr As String, StrDisp As String
' Turn Off Screen Updating
Application.ScreenUpdating = False
With ActiveDocument.Range
  With .Find
    .Text = "\<[Aa] href=([!\>]@)\>([!\<]@)\</a\>"
    .ClearFormatting
    .Replacement.ClearFormatting
    .Replacement.Text = ""
    .Forward = True
    .MatchWildcards = True
    .Wrap = wdFindStop
    .Execute
  End With
  Do While .Find.Found = True
    StrAddr = Replace(Replace(Replace(Split(Split(.Text, ">")(0), "=")(1), Chr(34), ""), Chr(147), ""), Chr(148), "")
    StrDisp = Split(Split(.Text, ">")(1), "<")(0)
    .Hyperlinks.Add Anchor:=.Duplicate, _
      Address:=StrAddr, TextToDisplay:=StrDisp
    .Collapse wdCollapseEnd
    .Find.Execute
  Loop
End With
' Restore Screen Updating
Application.ScreenUpdating = True
End Sub
Reply With Quote