I'm working on the following code, which will re-format a cell containing a link based on whether or not the link works when it is clicked:
Private Sub worksheet_followhyperlink(ByVal HL As HYPERLINK)
Dim linkReq As Object
Dim linkStatus As Integer
Application.ScreenUpdating = False
On Error GoTo linkError
Set linkReq = New MSXML2.XMLHTTP60
With linkReq
.Open "GET", HL.address, False
.Send
End With
linkStatus = linkReq.Status
If linkStatus = 404 Then HL.Parent.Interior.Color = rgbPink
If linkStatus <> 404 Then HL.Parent.Interior.Pattern = xlNone
If HL.Parent.Interior.Pattern = xlNone Then GoTo exitSub
Application.ScreenUpdating = True
MsgBox("Link is broken")
exitSub:
Application.ScreenUpdating = True
Exit Sub
linkError:
linkStatus = 404
Resume Next
End Sub
The code worked great yesterday! But now, it's returning everything as '404' and marking the cells pink, even if the links work. Debugging reveals that the value of HL.address is "folder/Document.pdf" instead of "https://website/folder/Document.pdf". This excel document is hosted on "https://website" through sharepoint.
The code not working because of the truncation.
Is there a way to extract a full url from an excel hyperlink, without truncation, regardless of the size of the url?