Thread: [Solved] Remove Hyperlink
View Single Post
 
Old 12-09-2013, 05:43 PM
macropod's Avatar
macropod macropod is offline Windows 7 32bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,467
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Try the following macro:
Code:
Sub Demo()
Dim i As Long, StrTxt As String, StrOut As String
With ActiveDocument
  For i = .Hyperlinks.Count To 1 Step -1
    With .Hyperlinks(i)
      StrTxt = .TextToDisplay
      If StrTxt Like "[#@]*" Then
        .Range.Fields(1).Unlink
      ElseIf InStr(StrTxt, "@") > 0 Then
        StrOut = Mid(StrTxt, InStr(StrTxt, "@") - 1, Len(StrTxt))
        .Range.InsertAfter StrOut
        .TextToDisplay = Left(StrTxt, InStr(StrTxt, "@") - 2)
      End If
    End With
  Next
End With
End Sub
Note: some/most of the @ symbols were actually within a hyperlink rather than being its start, so that added an extra level of complication to the code
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote