我相对较不熟悉编码,正在尝试测试URL是否存在。我目前在下面有一些代码。
基于我的了解,我对它为什么返回False并显示而不返回True感到困惑。
Sub Test()
If URLExists("www.google.com") = True Then
MsgBox "True"
Else
MsgBox "False"
End If
End Sub
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
就像我说过的那样,我希望它返回True,但是一直都为False。任何澄清将不胜感激。
谢谢!