Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vba 将动态数据传递到Internet Explorer-创建多个登录_Vba_Excel - Fatal编程技术网

Vba 将动态数据传递到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

我想用Excel中的宏自动化Internet Explorer。
我能用硬编码数据做到这一点。我想从另一张纸上复制数据

示例:-我想在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
这可能行得通