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.
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.