我在excel中的VBA代码可以使用F8,但不能使用F5。下面是我的代码。
Sub CheckFileExists()
'Clear content
Windows("FilesExists.xlsm").Activate
Sheets("FilesExists").Select
Range("C50").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.ClearContents
Range("C50").Select
Windows("FilesExists.xlsm").Activate
Sheets("FilesExists").Select
Set ws = ThisWorkbook.Worksheets("FilesExists")
Dim webURL As String
Numrows = Range("B50", Range("B50").End(xlDown)).Rows.Count
Range("B50").Select
With ws
For x = 1 To Numrows
'delay (3)
CurrValue = ActiveCell.Value
webURL = CurrValue
If IsURLGood(webURL) = True Then
.Range("C" & (ActiveCell.Row)).Value = "EXISTS"
Else
.Range("C" & (ActiveCell.Row)).Value = "CHECK"
End If
ActiveCell.Offset(1, 0).Select
Next
End With
'Improves performance/stability
Call OptimizeCode_End
End Sub
Public Function IsURLGood(URL As String) As Boolean 'Application.Calculation = xlCalculationManual
Dim WinHttpReq_Today As Object
Set WinHttpReq_Today = CreateObject("Microsoft.XMLHTTP")
On Error GoTo IsURLGoodError
WinHttpReq_Today.Open "HEAD", URL
WinHttpReq_Today.send
If WinHttpReq_Today.Status = 200 Then
IsURLGood = True
Else
IsURLGood = False
End If
'Application.Calculation = xlCalculationAutomatic
Exit Function
IsURLGoodError:
IsURLGood = False
'Application.Calculation = xlCalculationAutomatic
End Function
我真的希望有人能帮助,所以我将能够设置自动执行转发每日邮件与文件是否存在。-)
此致索伦·西格·米克尔森
1条答案
按热度按时间tkclm6bt1#
HTTP请求(
GET
)