使用 VBA 登录银行
Login to Bank using VBA
我希望完成 2 个简单的任务。输入密码,将用户名和密码提交到https://ktt.key.com
我目前可以在用户名选项卡中显示我的名字,但输入密码时遇到问题。也请提供提交方式。感谢您的帮助。
这是我目前所拥有的...
Sub login()
Dim IE As Object
Dim HTMLDoc As Object
Dim objCollection As Object
Const navOpenInNewTab = &H800
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
IE.Navigate "https://ktt.key.com/ktt/cmd/logon"
Do While IE.Busy Or IE.ReadyState <> 4: Loop
Set HTMLDoc = IE.document
Set htmlColl = HTMLDoc.getElementsByName("moduleTarget")
With HTMLDoc
HTMLDoc.getElementById("userId").Value = "xxxxx"
HTMLDoc.getElementByName("moduleTarget").Value = "xxxxxx"
End With
End Sub
我注意到您将 objCollection 设置为一个对象,所以我将使用它来填充您的密码字段。
变化:
With HTMLDoc
HTMLDoc.getElementById("userId").Value = "xxxxx"
HTMLDoc.getElementByName("moduleTarget").Value = "xxxxxx"
End With
收件人:
With HTMLDoc
HTMLDoc.getElementById("userId").Value = "xxxxx"
End With
然后在下面粘贴:
Set objCollection = HTMLDoc.getelementsbyname("txtPassword")
objCollection(0).Value = "1234" 'This is your password
那么它做了什么,它为 txtPassword 元素集合设置了一个新对象。然后它获取第一个索引("txtPassword" 下只有一个索引)并分配您选择的值。完整代码(从 With HTMLDoc
开始)应如下所示:
With HTMLDoc
HTMLDoc.getElementById("userId").Value = "xxxxx"
End With
Set objCollection = HTMLDoc.getelementsbyname("txtPassword")
objCollection(0).Value = "1234" 'This is your password
让我知道这是否适合你。
我希望完成 2 个简单的任务。输入密码,将用户名和密码提交到https://ktt.key.com
我目前可以在用户名选项卡中显示我的名字,但输入密码时遇到问题。也请提供提交方式。感谢您的帮助。
这是我目前所拥有的...
Sub login()
Dim IE As Object
Dim HTMLDoc As Object
Dim objCollection As Object
Const navOpenInNewTab = &H800
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
IE.Navigate "https://ktt.key.com/ktt/cmd/logon"
Do While IE.Busy Or IE.ReadyState <> 4: Loop
Set HTMLDoc = IE.document
Set htmlColl = HTMLDoc.getElementsByName("moduleTarget")
With HTMLDoc
HTMLDoc.getElementById("userId").Value = "xxxxx"
HTMLDoc.getElementByName("moduleTarget").Value = "xxxxxx"
End With
End Sub
我注意到您将 objCollection 设置为一个对象,所以我将使用它来填充您的密码字段。
变化:
With HTMLDoc
HTMLDoc.getElementById("userId").Value = "xxxxx"
HTMLDoc.getElementByName("moduleTarget").Value = "xxxxxx"
End With
收件人:
With HTMLDoc
HTMLDoc.getElementById("userId").Value = "xxxxx"
End With
然后在下面粘贴:
Set objCollection = HTMLDoc.getelementsbyname("txtPassword")
objCollection(0).Value = "1234" 'This is your password
那么它做了什么,它为 txtPassword 元素集合设置了一个新对象。然后它获取第一个索引("txtPassword" 下只有一个索引)并分配您选择的值。完整代码(从 With HTMLDoc
开始)应如下所示:
With HTMLDoc
HTMLDoc.getElementById("userId").Value = "xxxxx"
End With
Set objCollection = HTMLDoc.getelementsbyname("txtPassword")
objCollection(0).Value = "1234" 'This is your password
让我知道这是否适合你。