Error 424 In VB - excel

I am trying to create the Automation using VB to log in to website by using the User ID & Password, but its giving me error 424 Object required as shown below the VB Code
Sub Test()
Set IE = CreateObject("InternetExplorer.application")
IE.Visible = True
IE.Navigate ("https://appsglobal.nike.com/Citrix/AppsGlobal/auth/login.aspx" & ActiveCell)
Do
If IE.ReadyState = 4 Then
IE.Visible = False
Exit Do
Else
DoEvents
End If
Loop
IE.Document.Forms(0).all("User Name").Value = "UserID"
IE.Document.Forms(0).all("Password").Value = "Password"
IE.Document.Forms(0).submit
End Sub

Related

Website to excel data fetching

Can anyone please help in fetching data from website to excel using VBA, i need property address in excel cell:
Option Explicit
Sub test()
Dim ie As New InternetExplorer
ie.navigate "xyz.org"
ie.Visible = True
Do
DoEvents
Loop Until ie.readyState = READYSTATE_COMPLETE
Dim doc As HTMLDocument
Set doc = ie.document
ie.document.all("input-search-field").Value = Range("b1").Value
Dim obj As Object
For Each obj In ie.document.getElementsByTagName("BUTTON")
If obj.className = "btn btn-default search-button" Then
obj.Click
Exit For
Do
DoEvents
Loop Until ie.readyState = READYSTATE_COMPLETE
Dim isPropertyAddr As Boolean
isPropertyAddr = ie.document.getElementById("LoanObject").ie.document.getelementbytagname("SPAN")
isPropertyAddr = True
Debug.Print ie.document.getattributes("classname"), ie.document.getattributes("tagname")
MsgBox obj.innerText
dom code
Try something like this
IsAddressFound = False
For Each obj In ie.document.getElementById("LoanObject").getElementsByTagname("SPAN")
If InStr(obj.Innertext, "Property Address") > 0 Then
IsAddressFound = True
End If
If IsAddressFound Then
Debug.Print obj.Innertext 'Your address populates here
IsAddressFound = False
End If
Next
Thanks

VBA Run-time error '-2147417848 (80010108)'

I am trying to connect to a webpage and enter a value but it's giving me the runtime error as follows:
Run-time error '-2147417848 (80010108)'.
Here is my code:
Sub OpenMyURL()
Dim eRow As Long
Dim ele As Object
Set objIE = CreateObject("InternetExplorer.Application")
myjobtype = InputBox("Enter offer name")
With objIE
.Visible = True
.navigate "visualreports.aexp.com/#/views/AmexOffersPersistenceReport/…; 'getting runtime error here "
Do While .Busy Or .readyState <> 4
DoEvents
Loop
Set what = objIE.document.getElementsByName("omniboxTextBox")
what.Item(0).Value = myjobtype
.document.getElementById("JobsButton").Click
Do While .Busy Or .readyState <> 4
DoEvents
Loop
Set objIE = Nothing
End Sub

Navigating through websites

My code is able to interact with the first webpage it brings up, but then as soon as i navigate away from it, my code gives me a '424' object required error. Here is an example.
EX: go to yahoo.com - search for 'Earth' - click on the Yahoo logo to return to the yahoo homepage
Sub InternetPractice()
Dim ie As InternetExplorer
Set ie = New InternetExplorer
ie.Visible = True
ie.navigate "https://www.yahoo.com"
Do While ie.Busy = True Or ie.readyState <> 4: DoEvents: Loop
ie.document.getElementById("uh-search-box").Value = "Earth"
ie.document.getElementById("uh-search-button").Click
Do While ie.Busy = True Or ie.readyState <> 4: DoEvents: Loop
ie.document.getElementById("logo").Click
End Sub
Using VBA with the internet is new to me and any help is appreciated!
EDIT:
I think you are not giving enough time for ie to load... It is working for me.
So you can try this code that gives more time and try to load 3 times before aborting.
Option Explicit
Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Sub InternetPractice2()
Dim IE As InternetExplorer
Dim HTMLDoc As HTMLDocument
Dim logo As Object
Dim n As Long
Set IE = New InternetExplorer 'Set IE = CreateObject("InternetExplorer.Application")
With IE
.Silent = True
.Visible = True
.Navigate "https://www.yahoo.com"
End With
WaitIE IE, 5000
Set HTMLDoc = IE.Document
HTMLDoc.getElementById("uh-search-box").Value = "Earth"
HTMLDoc.getElementById("uh-search-button").Click
load:
WaitIE IE, 10000
Set logo = HTMLDoc.getElementById("logo")
If Not logo Is Nothing Then
logo.Click
ElseIf logo Is Nothing And n < 4 Then
n = n + 1
GoTo load
End If
WaitIE IE, 5000
'Set ie to Nothing
IE.Quit
Set IE = Nothing
End Sub
Sub WaitIE(IE As Object, Optional time As Long = 250)
'Code from: https://stackoverflow.com/questions/33808000/run-time-error-91-object-variable-or-with-block-variable-not-set
Dim i As Long
Do
Sleep time
Debug.Print CStr(i) & vbTab & "Ready: " & CStr(IE.READYSTATE = 4) & _
vbCrLf & vbTab & "Busy: " & CStr(IE.Busy)
i = i + 1
Loop Until IE.READYSTATE = 4 Or Not IE.Busy
End Sub
Original Answer
Try closing ie in the end of the code and add some delay, because if you step the code with F8, you will see that it works:
Sub InternetPractice2()
Dim ie As InternetExplorer
Set ie = New InternetExplorer
ie.Visible = True
ie.navigate "https://www.yahoo.com"
Do While ie.Busy = True Or ie.READYSTATE <> 4: DoEvents: Loop
ie.Document.getElementById("uh-search-box").Value = "Earth"
ie.Document.getElementById("uh-search-button").Click
'Add delay After .Click
Do While ie.Busy = True Or ie.READYSTATE <> 4: DoEvents: Loop
Application.wait Now+Timevalue("00:00:05")
ie.Document.getElementById("logo").Click
'Set ie to Nothing
Set ie = Nothing
End Sub
Also close all iexplorer.exe on Windows Task Manager.

IE.Document.getElementsByName("name").Value = "Value" not working

When I try and do this, it throws a number of errors at me depending on other bits of my code, such as the method is not associated with that object or an unspecified error.
I am trying to go down a list of Excel cells with strings and use a web form to search for those strings.
My code currently looks like this:
Sub YSF_automation()
Application.ScreenUpdating = False
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
IE.Navigate "URL"
While IE.Busy
DoEvents
Wend
IE.Document.getElementsByName("ElementName")(0).Value = "test"
End Sub
Try the below
Option Explicit
Dim IE as Object
Sub YSF_automation()
Application.ScreenUpdating = False
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
IE.Navigate "URL"
While IE.Busy
DoEvents
Wend
set document = IE.document
with document
.getElementsByName("ElementName")(0).value="test"
end with
End Sub

VBA to select list in IE

I've been trying to use VBA to open an IE window and select from one of the dropdown list showing bwin but failed. Any advice?
Private Sub OKButton_Click()
Dim ie As Object
Set ie = CreateObject("InternetExplorer.Application")
With ie
.Silent = True
.Visible = True
.Navigate "http://www.yahoo.com/"
End With
While ie.ReadyState <> 4 Or ie.Busy: DoEvents: Wend
Set AvailableLinks = oIE.document.getelementbyid("list-listing").getelementsbytagname("a")
For Each cLink In AvailableLinks
If cLink.innerhtml = "????" Then
cLink.Click
End If
Next cLink
End Sub

Resources