excel - 在“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```
解决方案
推荐阅读
- html - 在 CSS 中结合悬停和之后的部署动画
- c++ - 为什么我的排名二叉搜索树实现如此缓慢?
- java - 减少错误最有用的 Intellij IDEA 插件是什么?
- android - Inoic 构建 android 失败:任务:capacitor-cordova-android-plugins:compileDebugJavaWithJavac FAILED
- javascript - 使用字典键值动态创建 JSON
- flutter - Flutter 中的堆叠 ListView
- python-3.x - Python 装饰/导入....如何消除此解决方案中的 __init__.py ?
- mysql - 如何在同一个语句中组合 like 和 between (laravel Query Builder/model)
- node.js - 如何创建所需的属性并将其用于 API?
- charts - chartJS generateLegend()