Quote:
Originally Posted by PRA007
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