检查Excel中是否存在损坏的超链接

use*_*685 4 sorting excel vba hyperlink

我有一个很大的超链接列表(加上几个无意义的单元格),我需要检查.我需要知道哪些链接仍处于活动状态,哪些链接不再存在或返回404(或其他)错误.我一直在使用此条目中的建议:在Excel中使用VBA对死去的超链接进行排序?它在一小部分链接中运行良好,其中一些我故意打破了自己.但是,现在我尝试在我的实际超链接列表中使用相同的宏,它根本不起作用!我手动检查了一些,发现404错误的链接.再一次,当我故意错误地输入其中一个地址时,它会选择它,但它不会在已经破坏的列表中找到任何地址.

我对宏来说是全新的,我真的在黑暗中磕磕绊绊.任何帮助/建议将非常感谢!

tbu*_*bur 6

我已经使用了一段时间,它一直在为我工作.

Sub Audit_WorkSheet_For_Broken_Links()

If MsgBox("Is the Active Sheet a Sheet with Hyperlinks You Would Like to Check?", vbOKCancel) = vbCancel Then

    Exit Sub

End If

On Error Resume Next
For Each alink In Cells.Hyperlinks
    strURL = alink.Address

    If Left(strURL, 4) <> "http" Then
        strURL = ThisWorkbook.BuiltinDocumentProperties("Hyperlink Base") & strURL
    End If

    Application.StatusBar = "Testing Link: " & strURL
    Set objhttp = CreateObject("MSXML2.XMLHTTP")
    objhttp.Open "HEAD", strURL, False
    objhttp.Send

    If objhttp.statustext <> "OK" Then

        alink.Parent.Interior.Color = 255
    End If

Next alink
Application.StatusBar = False
On Error GoTo 0
MsgBox ("Checking Complete!" & vbCrLf & vbCrLf & "Cells With Broken or Suspect Links are Highlighted in RED.")

End Sub
Run Code Online (Sandbox Code Playgroud)