首页 文章

Excel VBA代码不能与Internet Explorer 11一起使用

提问于
浏览
1

我有一个vba代码,可以将数据从Excel工作表上传到网站 . 但是,代码在IE浏览器8中工作正常,但它在win8 IE浏览器11上不起作用 . 它给出错误438(“对象不支持此属性或方法”)并且文本字段保持空白 . 以下是代码的一部分:

Dim ie As New InternetExplorer

Dim DOCS作为HTMLDocument

ie.Navigate "http://uhs.edu.pk/results/etr2015.php"

ie.Visible = True

的DoEvents

循环直到ie.readyState = READYSTATE_COMPLETE

ie.Document.getElementsName(“ROLLNO”) . Value =“55”

需要帮助来解决此问题 .

1 回答

  • 2

    这应该适合你 .

    Sub testIE()
    Dim ie As Object
    Dim objCollection As Object
    Dim i As Integer
    
    'Create InternetExplorer Object
    Set ie = CreateObject("InternetExplorer.Application")
    
        ie.Visible = True
        'Load the login page
        ie.navigate "http://uhs.edu.pk/results/etr2015.php"
    
        'Wait until the page is ready
        Do While ie.busy
            Application.Wait DateAdd("s", 1, Now)
        Loop
    
        'Get all the elements with input tag name
        Set objCollection = ie.Document.getElementsByTagName("input")
    
        i = 0
    
        'Loop through all elements and find login form and fill it
        While i < objCollection.Length
            'Login name
            If objCollection(i).Name = "rollno" Then
                objCollection(i).Value = "55"
            End If  
        i = i + 1
        Wend
    
    
    
        'Clean up
        Set ie = Nothing
    
    
    End Sub
    

    如果你还想自动化serach按钮,这应该可以解决问题

    Sub testIE()
    Dim ie As Object
    Dim objCollection As Object
    Dim objElement As Object
    Dim i As Integer
    
    'Create InternetExplorer Object
    Set ie = CreateObject("InternetExplorer.Application")
    
        ie.Visible = True
        'Load the login page
        ie.navigate "http://uhs.edu.pk/results/etr2015.php"
    
        'Wait until the page is ready
        Do While ie.busy
            Application.Wait DateAdd("s", 1, Now)
        Loop
    
        'Get all the elements with input tag name
        Set objCollection = ie.Document.getElementsByTagName("input")
    
        i = 0
    
        'Loop through all elements and find login form and fill it
        While i < objCollection.Length
            'Login name
            If objCollection(i).Name = "rollno" Then
                objCollection(i).Value = "55"
            End If
    
            'Store login button in object
            If objCollection(i).Type = "submit" Then
                Set objElement = objCollection(i)
            End If
    
        i = i + 1
        Wend
    
        'Click login
        objElement.Click
    
    
        'Clean up
        Set ie = Nothing
    
    
    End Sub
    

    用于从新页面获取数据的代码

    Sub testIE()
    Dim ie As Object
    Dim objCollection As Object
    Dim objElement As Object
    Dim i As Integer
    
    'Create InternetExplorer Object
    Set ie = CreateObject("InternetExplorer.Application")
    
        ie.Visible = False
        'Load the login page
        ie.navigate "http://uhs.edu.pk/results/etr2015.php"
    
        'Wait until the page is ready
        Do While ie.busy
            Application.Wait DateAdd("s", 1, Now)
        Loop
    
        'Get all the elements with input tag name
        Set objCollection = ie.Document.getElementsByTagName("input")
    
        i = 0
    
        'Loop through all elements and find login form and fill it
        While i < objCollection.Length
            'Login name
            If objCollection(i).Name = "rollno" Then
                objCollection(i).Value = "55"
            End If
    
            'Store login button in object
            If objCollection(i).Type = "submit" Then
                Set objElement = objCollection(i)
            End If
    
        i = i + 1
        Wend
    
        'Click login
        objElement.Click
    
        Do While ie.busy
            Application.Wait DateAdd("s", 1, Now)
        Loop
    
        Set objCollection = ie.Document.getElementsByTagName("tr")
    
    
        Range("A2").Value = Split(objCollection(23).innertext, "Sr. No.")(1)
    
        Range("B2").Value = Split(objCollection(24).innertext, "Roll No.")(1)
    
        Range("C2").Value = Split(objCollection(25).innertext, "Name of the Candidate")(1)
    
        Range("D2").Value = Split(objCollection(26).innertext, "Father's Name ")(1)
    
        Range("E2").Value = Split(objCollection(27).innertext, "Centre")(1)
    
        Range("F2").Value = Split(objCollection(28).innertext, "Entrance Test Marks ")(1)
    
        Range("G2").Value = Split(objCollection(29).innertext, "Total Marks")(1)
    
    
        'Clean up
        ie.Quit
        Set ie = Nothing
    
    
    End Sub
    

    希望这可以帮助你 :)

    另一页上的组合框解决方案 .

    Sub testIE()
    Dim ie As Object
    Dim objCollection As Object
    Dim objElement As Object
    Dim i As Integer
    
    'Create InternetExplorer Object
    Set ie = CreateObject("InternetExplorer.Application")
    
        ie.Visible = True
        'Load the login page
        ie.navigate "http://result.biselahore.com/"
    
        'Wait until the page is ready
        Do While ie.busy
            Application.Wait DateAdd("s", 1, Now)
        Loop
    
        'Get all the elements with input tag name
        Set objCollection = ie.Document.getElementsByTagName("Select")
    
        i = 0
    
        'Loop through all elements and find login form and fill it
        While i < objCollection.Length
    
            'either one of the methodes below works
            'If objCollection(i).Name = "session" Then objCollection(i).Value = 2
            If objCollection(i).Name = "session" Then objCollection(i).Item(2).Selected = True
    
            If objCollection(i).Name = "year" Then objCollection(i).Item(2).Selected = True
            i = i + 1
        Wend
    
        'Clean up
        Set ie = Nothing
    
    
    End Sub
    

相关问题