【发布时间】:2020-12-28 02:29:36
【问题描述】:
为了改进重复性工作,我尝试使用VBA访问公司正在使用的网站。
所以,我使用 VBA 编写代码。我检查它可以访问正常的网站,如谷歌,youtube...... 但是,我不知道为什么它无法访问公司网站。
VBA 停止了这一行
Set HTMLDoc = IE_ctrl.document
先谢谢你了。
我在 Normal 和 company 站点之间检查了一个不同的东西(VBA 本地值、类型)。 请查看以下 2 张图片。
Sub a()
Dim IE_ctrl As InternetExplorer
Dim HTMLDoc As HTMLDocument
Dim input_Data As IHTMLElement
Dim URL As String
URL = "https://www.google.com"
Set IE_ctrl = New InternetExplorer
IE_ctrl.Silent = True
IE_ctrl.Visible = True
IE_ctrl.navigate URL
Wait_Browser IE_ctrl
Set HTMLDoc = IE_ctrl.document
Wait_Browser IE_ctrl
Set input_Data = HTMLDoc.getElementsByClassName("text").Item
input_Data.Click
End Sub
Sub Wait_Browser(Browser As InternetExplorer, Optional t As Integer = 1)
While Browser.Busy
DoEvents
Wend
Application.Wait DateAdd("s", t, Now)
End Sub
- 正常站点(运行良好。) enter image description here
- 公司网站(操作错误。) enter image description here
【问题讨论】:
-
google 的
IE_control值是InternetExplorer/WebBrowser2,但对于您的站点,它只是InternetExplorer。我不知道这到底是什么意思。第一个想法是,当你完成它们时,确保你Set对象到Nothing。当他们为下一个网站重置时,也许这会有所帮助。还要确保 URL 正确。