View Single Post
 
Old 11-29-2015, 10:07 PM
macropod's Avatar
macropod macropod is offline Windows 7 64bit 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

Quote:
Originally Posted by PRA007 View Post
Please note that some of my EP Links doesn't contain pdf doc.
It would have been helpful had you advised that beforehand. Try:
Code:
Sub EPHYPERLINKDOWN()
Application.ScreenUpdating = False
Dim StrTxt As String, HttpReq As Object, i As Long
Set HttpReq = CreateObject("Microsoft.XMLHTTP")
With ActiveDocument.Range
  With .Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = "EP [0-9]{5,} [0-9A-Z]{1,2}"
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindStop
    .Format = False
    .MatchWildcards = True
    .Execute
  End With
  Do While .Find.Found
    If .Hyperlinks.Count > 0 Then
      HttpReq.Open "GET", .Hyperlinks(1).Name, False
      HttpReq.Send
      StrTxt = HttpReq.ResponseText
      i = InStr(StrTxt, "https://data.epo.org/publication-server/pdf-document")
      If i > 0 Then
        StrTxt = Mid(StrTxt, i, Len(StrTxt) - i)
        i = InStr(InStr(StrTxt, ".pdf") + 3, StrTxt, ".pdf")
        If i > 0 Then
          StrTxt = Replace(Left(StrTxt, i + 3), "amp;", "")
          .Hyperlinks(1).Address = StrTxt
        End If
      End If
    End If
    .Collapse wdCollapseEnd
    .Find.Execute
  Loop
End With
Set HttpReq = Nothing
Application.ScreenUpdating = True
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote