简体   繁体   English

Excel VBA代码不适用于Internet Explorer 11

[英]Excel VBA Code Not Working With Internet Explorer 11

I have a vba code which can upload the data from an excel sheet to a website. 我有一个VBA代码,可以将数据从Excel工作表上传到网站。 However, the code works fine in IE browser 8,but it does not work on a win8 IE browser 11. It gives error 438 ("Object Does'nt support this property or method") and text field remains blank. 但是,该代码在IE浏览器8中工作正常,但在win8 IE浏览器11上却无法正常工作。它显示错误438(“对象不支持此属性或方法”),并且文本字段保持空白。 Here are part of the code: 这是代码的一部分:

Dim ie As New InternetExplorer 昏暗即新InternetExplorer

Dim DOCS As HTMLDocument 将DOCS变暗为HTMLDocument

ie.Navigate " http://uhs.edu.pk/results/etr2015.php " 即。导航“ http://uhs.edu.pk/results/etr2015.php

ie.Visible = True ie.Visible = True

Do

DoEvents 的DoEvents

Loop Until ie.readyState = READYSTATE_COMPLETE 循环直到ie.readyState = READYSTATE_COMPLETE

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

Need help to resolve this problem. 需要帮助来解决此问题。

This Should Work for you. 这应该为您工作。

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

If you also want to automate the serach button this should do the trick 如果您还想自动执行搜索按钮,这应该可以解决问题

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

Code to also fetch data from new page 代码还可以从新页面获取数据

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

Hope this helps you out :) 希望这可以帮助你 :)

Solution for combobox on the other page. 其他页面上的组合框解决方案。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM