vba - Set doc = IE.document 返回自动化错误
问题描述
我正在尝试使用一组填充此表单(https://help.grab.com/merchant/vi-vn/360027910731-DJang-ky-tham-gia-chuong-trinh-khuyen-mai-cung-GrabFood) excel 数据,用 Excel 中的相应列填充表单的每个字段。我在 StackOverflow 和 Youtube 上看到了几个关于使用 VBA 打开 IE、导航和填写文本框的教程,我从中编写了这些代码。
当我运行此代码并且 Excel 返回一个错误消息框时出现问题
运行时错误 '-2147467259 (80004005) 自动化错误未指定错误。
我太业余了,无法诊断这些在 Youtube 上的各种视频上完美运行的代码。希望你们能帮助我:)
Sub IE()
Dim IE As InternetExplorerMedium
Set IE = New InternetExplorerMedium
Dim doc As HTMLDocument
Set doc = IE.document //The error I mentioned above is in this line
IE.Visible = True
IE.navigate "https://help.grab.com/merchant/vi-vn/360027910731-DJang-ky-tham-gia-chuong-trinh-khuyen-mai-cung-GrabFood"
Do While IE.Busy
DoEvents
Loop
For Each ele In IE.document.getElementsByClassName("ant-radio-input")
If ele.Value = ThisWorkbook.Sheets("Sheet1").Range("A1") Then ele.Click: Exit For
Next
doc.getElementById("phone").Value = ThisWorkbook.Sheets("Sheet1").Range("C2").Value
doc.getElementById("email").Value = ThisWorkbook.Sheets("Sheet1").Range("D2").Value
IE.Quit
End Sub
解决方案
在创建 IE 实例并加载文档之前,您无法设置 ie.document。
IE.Visible = True
IE.navigate "https://help.grab.com/merchant/vi-vn/360027910731-DJang-ky-tham-gia-chuong-trinh-khuyen-mai-cung-GrabFood"
While IE.Busy Or IE.ReadyState <> 4:DoEvents:Wend
Set doc = IE.document
推荐阅读
- c# - 在 DateTimeOffset 列而不是 DateTime(2) 中存储 UTC 日期有什么意义吗?
- python - ProgrammingError 1064 在 Python 中使用 MySQL 从现有表中执行 CREATE TABLE AS SELECT
- c++ - 是否可以使用前缀表示法调用 << 运算符?
- python - Jupyter 笔记本 - 无法安装
- css - 将 CSS 编辑为 ngb-datepicker (Angular)
- 3d - 3D人脸输入的格式是什么?
- swift - ARKit – 如何将 ARImageTrackingConfiguration 与 ARFaceTrackingConfiguration 结合使用?
- python - Python函数在调用时不返回reuslt,没有输出。我究竟做错了什么
- c# - 如何从 ac# 数组中的第二项切片元素?
- c++ - 实例化变量模板时要考虑代码的哪一部分?