gpt4 book ai didi

excel - 运行时错误 '9' : Subscript out of range -Error

转载 作者:行者123 更新时间:2023-12-03 09:05:12 30 4
gpt4 key购买 nike

我在 excel 中运行 VBA 以进行一些网络抓取,但在尝试访问 Google Chrome 时出现此错误。如何避免这种情况?我将单击调试,然后突出显示一行...

这是弹出错误的地方

This is where the error pops up

这是必须给出问题的突出显示的代码行

This is the highlighted line of code that must be giving the issue

Full Code in this picture

完整代码如下:

Private Sub time_sheet_filling()

Dim I As Long
Dim IE As Object
Dim doc As Object
Dim objElement As Object
Dim objCollection As Object

' Create InternetExplorer Object
Set IE = CreateObject("ChromeTab.ChromeFrame")
IE.Visible = True

' Send the form data To URL As POST binary request
IE.navigate "https://wistar.dispondo.net/#/login"

' Wait while IE loading...
Do While IE.Busy
Application.Wait DateAdd("s", 1, Now)
Loop

'Load the logon page
Set objCollection = IE.Document.getElementsByTagName("input")
I = 0
While I < objCollection.Length
If objCollection(I).Name = "username" Then
' Set text to enter
objCollection(I).Value = "MyUsername"
End If
If objCollection(I).Name = "password" Then
' Set text for password
objCollection(I).Value = "MyPasword"
End If
If objCollection(I).Type = "submit" And objCollection(I).Name = "btnSubmit" Then ' submit button clicking
Set objElement = objCollection(I)
End If
I = I + 1
Wend

objElement.Click ' click button to load the form

' Wait while IE re-loading...
Do While IE.Busy
Application.Wait DateAdd("s", 1, Now)
Loop

' Show IE
IE.Visible = True
Dim links, link
Dim n, j
Set links = IE.Document.getElementById("dgTime").getElementsByTagName("a")
n = links.Length
For j = 0 To n - 1 Step 2
links(j).Click
'I have some operations to be done will post another question for this

Next



End Sub

最佳答案

如果在代码运行时事件工作簿中没有名为“网站数据”的工作表,则会发生该错误。工作表名称不匹配,或者代码运行时另一个工作簿处于事件状态。

确保工作表名称正确,并明确引用它所在的工作簿(以便在代码运行时哪个工作簿处于事件状态并不重要)。如果“网站数据”表位于运行代码的工作簿中,则使用以下方法引用单元格中的值:

ThisWorkbook.Sheets("Website Data").Cells(1,1).Value

关于excel - 运行时错误 '9' : Subscript out of range -Error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59849951/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com