下面表格中的網址有的可以打開,有的不能打開
在Excel中按下 Alt + F11 鍵來打開VBA編輯器,選擇 插入 > 模塊,創建一個新的模塊,在新創建的模塊窗口中輸入以下代碼:
Function 測試網址(ByVal URL As String) As StringDim objHttpRequest As Object
Dim strResponse As String
Set objHttpRequest = CreateObject("MSXML2.ServerXMLHTTP.6.0")
On Error Resume Next
objHttpRequest.Open "GET", URL, False
objHttpRequest.Send
On Error GoTo 0
If objHttpRequest.Status = 200 Then
測試網址 = "有效網址"
Else
測試網址 = "無效網址"
End If
Set objHttpRequest = Nothing
End Function
關閉VBE編輯器(無需保存),回到Excel中,輸入函數 =測試網址(A2),回車,下拉菜單批量應用函數
注意:函數只支持HTTP和HTTPS協議。如果嘗試使用ftp://或file://等不支持的協議,函數將返回#VALUE!錯誤,省略https://正確的網址也會返回#VALUE!錯誤。