Vba 将动态数据传递到Internet Explorer-创建多个登录
我想用Excel中的宏自动化Internet Explorer。Vba 将动态数据传递到Internet Explorer-创建多个登录,vba,excel,Vba,Excel,我想用Excel中的宏自动化Internet Explorer。 我能用硬编码数据做到这一点。我想从另一张纸上复制数据 示例:-我想在Example.com网站中创建多个登录,并在工作表中复制用户名 我的Excel代码:- Sub Submit() Set objIE = CreateObject("InternetExplorer.Application") objIE.Top = 0 objIE.Left = 0 obj
我能用硬编码数据做到这一点。我想从另一张纸上复制数据 示例:-我想在Example.com网站中创建多个登录,并在工作表中复制用户名 我的Excel代码:-
Sub Submit()
Set objIE = CreateObject("InternetExplorer.Application")
objIE.Top = 0
objIE.Left = 0
objIE.Width = 800
objIE.Height = 600
objIE.AddressBar = 0
objIE.StatusBar = 0
objIE.Toolbar = 0
objIE.Visible = True 'We will see the window navigation
objIE.Navigate ("http://example.com")
Do
DoEvents
Loop Until objIE.ReadyState = 4
pageSource = objIE.Document.body.Outerhtml
objIE.Document.GetElementByID("ctl00_ContentPlaceHolder1_txtUserName").Value = "xyz"
objIE.Document.GetElementByID("ctl00_ContentPlaceHolder1_txtPassword").Value = "123"
objIE.Document.GetElementByID("ctl00_ContentPlaceHolder1_btnSubmit1").Click
End Sub
Excel中的数据
+------+---------------+
| User | Password |
+------+---------------+
| ABC | 123 |
| XYZ | 456 |
| XCZ | 777 |
+------+---------------+
将
User
和Password
作为Submit
sub的参数
Sub Submit(User as string, Password as string)
Set objIE = CreateObject("InternetExplorer.Application")
objIE.Top = 0
objIE.Left = 0
objIE.Width = 800
objIE.Height = 600
objIE.AddressBar = 0
objIE.StatusBar = 0
objIE.Toolbar = 0
objIE.Visible = True 'We will see the window navigation
objIE.Navigate ("http://example.com")
Do
DoEvents
Loop Until objIE.ReadyState = 4
pageSource = objIE.Document.body.Outerhtml
objIE.Document.GetElementByID("ctl00_ContentPlaceHolder1_txtUserName").Value = User
objIE.Document.GetElementByID("ctl00_ContentPlaceHolder1_txtPassword").Value = Password
objIE.Document.GetElementByID("ctl00_ContentPlaceHolder1_btnSubmit1").Click
End Sub
在另一个sub中调用此sub
Sub Login()
dim strUser as string
dim strPassword as string
dim intLastRow as integer
dim intRow as integer
intLastRow = Cells(Rows.Count, "A").End(xlUp).Row
For intRow = 2 to intLastRow
strUser = Worksheets("MySheet").Cells(intRow, 1).value
strPassword = Worksheets("MySheet").Cells(intRow, 2).value
call Submit(strUser, strPassword)
Next intRow
End Sub
这可能行得通