1
votes

I have a vba code which can upload the data from an excel sheet to a website. 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. Here are part of the code:

Dim ie As New InternetExplorer

Dim DOCS As HTMLDocument

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

ie.Visible = True

Do

DoEvents

Loop Until ie.readyState = READYSTATE_COMPLETE

ie.Document.getElementsName("ROLLNO").Value = "55"

Need help to resolve this problem.

1
When error raises, press debug, type in immediate window ? TypeName(ie), and post the output. Check this answer also. - omegastripes
After typing "? TypeName(ie)" into the immediate window I found the following message: IWebBrowser2 - Syed Atif
Thank you very much for your valuable reply. I also tried the following one it it worked exactly for what I wanted. ie.Document.forms("result").elements("rollno").Value = "12" - Syed Atif

1 Answers

2
votes

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