Checking for broken hyperlinks and no content in url in word

I’ve created a simple script to extract all hyperlink addresses from a Word document to check whether the links are accessible or broken. Sometimes, the hyperlink itself works perfectly, but the content it points to is broken. For instance, when I open the link, it might display messages like “Hmmm… can’t reach this page” or “Sorry, something went wrong, No item exists at”. In such cases, the link works, but the content is not accessible.
Is it possible to detect these kinds of links and consider them broken?
Thank you.

My full code

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code> Sub Hyperlinks()
Dim FILEPATH As String
Dim doc As Object
Dim objDoc As Object
Dim objHyperlink As Object
Dim hyperlinkAddress As String
Dim hyperlinkedText As String
Dim status As String
FILEPATH = Application.GetOpenFilename("Word Files (*.docx; *.doc), *.docx; *.doc", , "Please Select a Word File")
If FILEPATH = "False" Then Exit Sub
If FILEPATH <> "False" Then
Set doc = CreateObject("Word.Application")
doc.Visible = True
Set objDoc = doc.Documents.Open(FILEPATH)
End If
Dim i As Integer
i = 3
With objDoc
For Each objHyperlink In .Hyperlinks
hyperlinkedText = objHyperlink.Range.Text
Workbooks("Document Hyperlink Checker.xlsm").Sheets("Automation").Range("A" & i).Value = hyperlinkedText
If objHyperlink.Address <> "" Or objHyperlink.SubAddress <> "" Then
If objHyperlink.SubAddress <> "" Then
hyperlinkAddress = objHyperlink.SubAddress
Workbooks("Document Hyperlink Checker.xlsm").Sheets("Automation").Range("C" & i).Value = "Internal"
Else
hyperlinkAddress = objHyperlink.Address
Workbooks("Document Hyperlink Checker.xlsm").Sheets("Automation").Range("C" & i).Value = "External"
End If
Workbooks("Document Hyperlink Checker.xlsm").Sheets("Automation").Range("B" & i).Value = hyperlinkAddress
If InStr(1, hyperlinkAddress, "http", vbTextCompare) > 0 Then
status = CheckHyperlink(hyperlinkAddress)
Else
status = "N/A"
End If
Workbooks("Document Hyperlink Checker.xlsm").Sheets("Automation").Range("D" & i).Value = status
Else
Workbooks("Document Hyperlink Checker.xlsm").Sheets("Automation").Range("B" & i).Value = hyperlinkAddress
End If
i = i + 1
Next objHyperlink
End With
MsgBox ("Checking Completed")
End Sub
Function CheckHyperlink(url As String) As String
Dim http As Object
Set http = CreateObject("WinHttp.WinHttpRequest.5.1")
On Error GoTo ErrorHandler
http.Open "GET", url, False
http.send
If http.status = 200 Then
CheckHyperlink = "Valid"
Else
CheckHyperlink = "Broken"
End If
Exit Function
ErrorHandler:
CheckHyperlink = "Broken"
End Function
</code>
<code> Sub Hyperlinks() Dim FILEPATH As String Dim doc As Object Dim objDoc As Object Dim objHyperlink As Object Dim hyperlinkAddress As String Dim hyperlinkedText As String Dim status As String FILEPATH = Application.GetOpenFilename("Word Files (*.docx; *.doc), *.docx; *.doc", , "Please Select a Word File") If FILEPATH = "False" Then Exit Sub If FILEPATH <> "False" Then Set doc = CreateObject("Word.Application") doc.Visible = True Set objDoc = doc.Documents.Open(FILEPATH) End If Dim i As Integer i = 3 With objDoc For Each objHyperlink In .Hyperlinks hyperlinkedText = objHyperlink.Range.Text Workbooks("Document Hyperlink Checker.xlsm").Sheets("Automation").Range("A" & i).Value = hyperlinkedText If objHyperlink.Address <> "" Or objHyperlink.SubAddress <> "" Then If objHyperlink.SubAddress <> "" Then hyperlinkAddress = objHyperlink.SubAddress Workbooks("Document Hyperlink Checker.xlsm").Sheets("Automation").Range("C" & i).Value = "Internal" Else hyperlinkAddress = objHyperlink.Address Workbooks("Document Hyperlink Checker.xlsm").Sheets("Automation").Range("C" & i).Value = "External" End If Workbooks("Document Hyperlink Checker.xlsm").Sheets("Automation").Range("B" & i).Value = hyperlinkAddress If InStr(1, hyperlinkAddress, "http", vbTextCompare) > 0 Then status = CheckHyperlink(hyperlinkAddress) Else status = "N/A" End If Workbooks("Document Hyperlink Checker.xlsm").Sheets("Automation").Range("D" & i).Value = status Else Workbooks("Document Hyperlink Checker.xlsm").Sheets("Automation").Range("B" & i).Value = hyperlinkAddress End If i = i + 1 Next objHyperlink End With MsgBox ("Checking Completed") End Sub Function CheckHyperlink(url As String) As String Dim http As Object Set http = CreateObject("WinHttp.WinHttpRequest.5.1") On Error GoTo ErrorHandler http.Open "GET", url, False http.send If http.status = 200 Then CheckHyperlink = "Valid" Else CheckHyperlink = "Broken" End If Exit Function ErrorHandler: CheckHyperlink = "Broken" End Function </code>
    Sub Hyperlinks()
   Dim FILEPATH As String
   Dim doc As Object
   Dim objDoc As Object
   Dim objHyperlink As Object
   Dim hyperlinkAddress As String
   Dim hyperlinkedText As String
   Dim status As String
   FILEPATH = Application.GetOpenFilename("Word Files (*.docx; *.doc), *.docx; *.doc", , "Please Select a Word File")
   If FILEPATH = "False" Then Exit Sub
   If FILEPATH <> "False" Then
       Set doc = CreateObject("Word.Application")
       doc.Visible = True
       Set objDoc = doc.Documents.Open(FILEPATH)
   End If
   Dim i As Integer
   i = 3
   With objDoc
       For Each objHyperlink In .Hyperlinks
           hyperlinkedText = objHyperlink.Range.Text
           Workbooks("Document Hyperlink Checker.xlsm").Sheets("Automation").Range("A" & i).Value = hyperlinkedText
           If objHyperlink.Address <> "" Or objHyperlink.SubAddress <> "" Then
               If objHyperlink.SubAddress <> "" Then
                   hyperlinkAddress = objHyperlink.SubAddress
                   Workbooks("Document Hyperlink Checker.xlsm").Sheets("Automation").Range("C" & i).Value = "Internal"
               Else
                   hyperlinkAddress = objHyperlink.Address
                   Workbooks("Document Hyperlink Checker.xlsm").Sheets("Automation").Range("C" & i).Value = "External"
               End If
               Workbooks("Document Hyperlink Checker.xlsm").Sheets("Automation").Range("B" & i).Value = hyperlinkAddress
               If InStr(1, hyperlinkAddress, "http", vbTextCompare) > 0 Then
                   status = CheckHyperlink(hyperlinkAddress)
               Else
                   status = "N/A"
               End If
               Workbooks("Document Hyperlink Checker.xlsm").Sheets("Automation").Range("D" & i).Value = status
           Else
               Workbooks("Document Hyperlink Checker.xlsm").Sheets("Automation").Range("B" & i).Value = hyperlinkAddress
           End If
           i = i + 1
       Next objHyperlink
   End With
   MsgBox ("Checking Completed")
End Sub
Function CheckHyperlink(url As String) As String
   Dim http As Object
   Set http = CreateObject("WinHttp.WinHttpRequest.5.1")
   On Error GoTo ErrorHandler
   http.Open "GET", url, False
   http.send
   If http.status = 200 Then
       CheckHyperlink = "Valid"
   Else
       CheckHyperlink = "Broken"
   End If
   Exit Function
ErrorHandler:
   CheckHyperlink = "Broken"
End Function

Some screenshot :
First Example
Second Example

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật