Excel VBA,填写互联网表格,每个表格使用不同的URL

时间:2019-03-22 12:41:40

标签: excel vba web

我想在Internet上填写一个表格,每个表格都有自己的网址,将其保存在excel单元格中,并将该特定表格的所有数据保存在同一原始文件中,因此我想运行一个循环来输入数据,

IE.Navigate (url_name)

所以不知道如何将其设置为变量:我需要尽快获得帮助

这是代码

Sub FileInternetForm()

Dim IE As Object   
Set IE = CreateObject("InternetExplorer.Application")

'create new instance of IE. use reference to return current open IE if
'you want to use open IE window. Easiest way I know of is via title ba

Dim i As Integer

For i = 1 To 100  
    '''Go to page

    Dim url_name As String

    url_name = ActiveSheet.Cells(i, 1)

    If url_name = "" Then Exit Sub

    ''With url_name

    IE.Navigate (url_name)

    'go to web page listed inside quotes

    IE.Visible = True        

    While IE.busy    
        DoEvents 'wait until IE is done loading page.    
    Wend    
    ''End With

    '''''' start

    Set tbcno = IE.document.getElementById("tbcno")    
    tbcno.Value = ActiveSheet.Cells(i, 2)

    Set Name = IE.document.getElementById("name")    
    Name.Value = ActiveSheet.Cells(i, 3)

    Set Email = IE.document.getElementById("email")    
    Email.Value = ActiveSheet.Cells(i, 4)

    Set mobile = IE.document.getElementById("mobile")    
    mobile.Value = ActiveSheet.Cells(i, 5)

    Set gender = IE.document.getElementById("gender")    
    gender.Value = ActiveSheet.Cells(i, 6)

    Set licenseno = IE.document.getElementById("licenseno")    
    licenseno.Value = ActiveSheet.Cells(i, 7)

    Set girno = IE.document.getElementById("girno")    
    girno.Value = ActiveSheet.Cells(i, 8)

    Set panno = IE.document.getElementById("panno")    
    panno.Value = ActiveSheet.Cells(i, 9)

    Set haddress = IE.document.getElementById("haddress")    
    haddress.Value = ActiveSheet.Cells(i, 10)            

    Set hcity = IE.document.getElementById("hcity")    
    hcity.Value = ActiveSheet.Cells(i, 11)

    Set hpin = IE.document.getElementById("hpin")    
    hpin.Value = ActiveSheet.Cells(i, 12)

    Set hstate = IE.document.getElementById("hstate")    
    hstate.Value = ActiveSheet.Cells(i, 13)

    Set oaddress = IE.document.getElementById("oaddress")    
    oaddress.Value = ActiveSheet.Cells(i, 14)            

    Set ocity = IE.document.getElementById("ocity")    
    ocity.Value = ActiveSheet.Cells(i, 15)

    Set opin = IE.document.getElementById("opin")    
    opin.Value = ActiveSheet.Cells(i, 16)

    Set lal = IE.document.getElementById("lal")    
    lal.Value = ActiveSheet.Cells(i, 17)            

    Set mrnno = IE.document.getElementById("mrnno")    
    mrnno.Value = ActiveSheet.Cells(i, 18)

    Set af = IE.document.getElementById("af")    
    af.Value = ActiveSheet.Cells(i, 19)

    Set nri = IE.document.getElementById("nri")    
    nri.Value = ActiveSheet.Cells(i, 20)

    Set cp = IE.document.getElementById("cp")    
    cp.Value = ActiveSheet.Cells(i, 21)

    'Click Button '                
    IE.document.getElementsByClassName("btn btn-info btn-fill")(0).Click

    ''Close Ie                
    IE.Quit

    Set IE = Nothing

Next i

End Sub

1 个答案:

答案 0 :(得分:1)

艾哈迈德,您正在循环中关闭IE浏览器。