gpt4 book ai didi

vba - 使用VBA控制IE登录网站

转载 作者:行者123 更新时间:2023-12-04 20:42:05 25 4
gpt4 key购买 nike

我是新手,但我正在练习,在我看来,登录我研究所的网站应该是世界上最简单的事情。正确的?好吧,这让我发疯了。

具体来说,该程序在
page.Document.getElementById("edit-name").Value = 1234
运行时错误 424“需要对象”

另外,当我输入“页面”时,我不确定这是否相关。 VBA 编辑器提供了一个选项列表,我选择了 Document。当我输入第二个“。”获取“page.Document”。然后我没有得到进一步的选项列表。

这是完整的程序,感谢您的帮助

Public Sub MyLogin()

'This uses early binding
'In menu at top of page - Tools...Reference.... Microsoft Internet Controls and Microsoft HTML Object Library must both be ticked



Dim page As InternetExplorer
Set page = New InternetExplorer
page.Visible = True

Dim MyLink As Object

'Login at Institute website
page.Navigate "http://www.actuaries.org.uk/"


Do While page.Busy Or page.ReadyState <> 4
DoEvents
Loop



For Each MyLink In page.Document.Links
If InStr(MyLink.href, "/user") Then MyLink.Click: Exit For
Next MyLink

Do While page.Busy Or page.ReadyState <> 4
DoEvents
Loop

'Are now at the login page
'Enter username, password and click


page.Document.getElementById("edit-name").Value = 1234
page.Document.getElementById("edit-pass").Value = "01/01/1977"
page.Document.getElementById("edit-submit").Click




End Sub

最佳答案

Specifically, the program fails at page.Document.getElementById("edit-name").Value = 1234



那条线没有错。

我能想到的一个原因是您的 For不执行循环。为避免这种情况,请直接导航到相关的 url .这个修剪过的版本适合我。

enter image description here
Sub Sample()
Dim sUrl As String: sUrl = "https://www.actuaries.org.uk/user"
Dim ie As Object

Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = True

ie.navigate sUrl

Do While ie.readystate <> 4: DoEvents: Loop

ie.Document.getElementById("edit-name").Value = 1234
End Sub

关于vba - 使用VBA控制IE登录网站,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30959574/

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