首页 > 解决方案 > 在“Recruiting.UsedRange.Offset(1).ClearContents”线上获取对象错误

问题描述

我不断得到

错误 424

Recruiting.UsedRange.Offset(1).ClearContents

我不知道我做错了什么。我是 VBA 编码的新手,无论我如何尝试解决问题,我都失败了。

Sub RecruitingRoster()
Dim C As Object, H As Object, S As Object, D As Object, x64 As Object, WinHttpReq As Object, recruitWF As Object
 Dim objIE As InternetExplorer
 Dim url$, recruit As Worksheet, src As Worksheet, cc As Worksheet, SourceWS As Worksheet
 Dim fc$, badge$, myURL$, pvt$, Source$
 Dim j As Long, RowCounter As Long, LastRow As Long, LastColumn As Long, Section As Long
 Dim SRange$, Destination
   
    Set H = CreateObject("WinHTTP.WinHTTPRequest.5.1")
    Set D = CreateObject("HTMLFile")
    Set S = CreateObject("ADODB.Stream")
    Set C = CreateObject("New:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}")
    
    
    Recruiting.UsedRange.Offset(1).ClearContents
    With H
        .Open "GET", "https://hrwfs.hershey.com/?Operation=empInfoByUid&ContentType=JSON&employeeUid=" & Environ("USERNAME")
        .send
        .WaitForResponse
    End With
   
    badge = Split(Split(H.responseText, "employeeBarcode"":""")(1), Chr(34))(0)
        
    'fc = Sheet1.[B1]
    
    fc = "DFW8/9"
       
    With H
        .Open "POST", "http://fcmenu-iad-regionalized.corp.hershey.com/do/login"
        .setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
        .setRequestHeader "Content-Length", Len("badgeBarcodeId=" & badge)
        .send "badgeBarcodeId=" & badge
    End With

    With H
        .SetAutoLogonPolicy 0
        .Open "GET", "https://rds.corp.hershey.com/rawdata/headcount/ishepard?"
        .SetTimeouts 0, 0, 0, 0
        .send
    End With
    
    Set recruit = Recruiting

Application.ScreenUpdating = False


S.Open
S.Type = 1
S.Write H.responseBody
S.SaveToFile Environ("TEMP") & "\Data.csv"
S.Close

recruit.Cells.ClearContents

Workbooks.Open Environ("TEMP") & "\Data.csv"
ActiveSheet.UsedRange.Copy Destination:=recruit.Range("A1")
ActiveWorkbook.Close False
Kill Environ("TEMP") & "\Data.csv"
End Sub```

标签: excelvba

解决方案


推荐阅读