I am working on the following code, which will reformat the cell containing the link, based on whether 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
Today the code has proven itself! But now it returns everything as "404" and marks the cells pink, even if the links work. Debugging shows 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 via sharepoint.
The code does not work due to truncation.
Is there a way to extract the full url from an excel hyperlink without truncation, regardless of the size of the url?
source share