VBA 上的对象必需错误(使用 VBA 提交 IE 表单)
Object Required Error on VBA (submitting IE form using VBA)
几个小时前,我的代码运行良好。但是当我现在打开文档并 运行 它时,我收到错误消息:
Run-time error '424': Object required
这是我的代码:
Dim ieApp As New SHDocVw.InternetExplorer
ieApp.Visible = True
ieApp.Navigate = "<url here; sorry, its confidential>"
Do While ieApp.Busy And Not ieApp.ReadyState = READYSTATE_COMPLETE
DoEvents
Loop
Dim ieElement As Object
Set ieElement = ieApp.Document.getElementById("i_specialist")
ieElement.Value = "TestValue"
错误指向:
Set ieElement = ieApp.Document.getElementById("i_specialist")
我真的不知道哪里出了问题。我在想两个可能的原因:
- 对象类型错误
- 加载代码找不到字段的页面出错
感谢任何帮助!谢谢!
您是否在 html 文档页面中检查过是否存在 ID 为 i_specialist 的 html 元素?
无论如何,当我使用 htmlElements 时,我就是这样做的……值得一试……
Set ie = CreateObject("InternetExplorer.Application")
With ie
.Visible = True
.Navigate "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
Do Until .ReadyState = 4
DoEvents
Loop
.document.all.Item("i_specialist").Value = "TestValue"
End With
几个小时前,我的代码运行良好。但是当我现在打开文档并 运行 它时,我收到错误消息:
Run-time error '424': Object required
这是我的代码:
Dim ieApp As New SHDocVw.InternetExplorer
ieApp.Visible = True
ieApp.Navigate = "<url here; sorry, its confidential>"
Do While ieApp.Busy And Not ieApp.ReadyState = READYSTATE_COMPLETE
DoEvents
Loop
Dim ieElement As Object
Set ieElement = ieApp.Document.getElementById("i_specialist")
ieElement.Value = "TestValue"
错误指向:
Set ieElement = ieApp.Document.getElementById("i_specialist")
我真的不知道哪里出了问题。我在想两个可能的原因: - 对象类型错误 - 加载代码找不到字段的页面出错
感谢任何帮助!谢谢!
您是否在 html 文档页面中检查过是否存在 ID 为 i_specialist 的 html 元素? 无论如何,当我使用 htmlElements 时,我就是这样做的……值得一试……
Set ie = CreateObject("InternetExplorer.Application")
With ie
.Visible = True
.Navigate "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
Do Until .ReadyState = 4
DoEvents
Loop
.document.all.Item("i_specialist").Value = "TestValue"
End With