我有一个简单的脚本来登录网页,但现在我需要构建一个VB脚本,如果我单击一个按钮
- 它应该登录到网页
- 将用户名和密码从Excel工作表复制到网页
- 然后点击登录按钮登录网页
在脚本中输入用户名和密码的位置。
像下面一样 .getElementbyid("UserID"(.value =range("a1"(.valuePW也是如此。.getelementbyid("Password"(.value =range("a2"(.value
考虑使用它。
Set ie = CreateObject("InternetExplorer.application")
' Get username and password from worksheet. Not very secure, but this way the credentials are always sitting in the same spot and the user doesn't have to enter these each time.
' Alternative is to use an input box toprompt the user for crednetials.
UserName = Worksheets("ControlSheet").Range("A1").Value
Password = Worksheets("ControlSheet").Range("A2").Value
With ie
.Visible = True
.navigate "YOUR_1ST_URL_HERE"
' Wait for the page to fully load; you can't do anything if the page is not fully loaded
Do While .Busy Or _
.readyState <> 4
DoEvents
Loop
On Error Resume Next
'Credentials are passed to the site and the button is clicked (by the code).
ie.document.forms(0).all("username").Value = UserName
ie.document.forms(0).all("password").Value = Password
ie.document.forms(0).submit.Click
' Wait for the page to fully load; you can't do anything if the page is not fully loaded
Do While .Busy Or _
.readyState <> 4
DoEvents
Loop
.navigate "YOUR_2ND_URL_HERE"
Do While .Busy Or _
.readyState <> 4
DoEvents
Loop