My code was working perfectly fine a few hours ago. But when I open the document now and run it, I get the error:
Run-time error '424': Object required
Here's my code:
Dim ieApp As New SHDocVw.InternetExplorer
ieApp.Visible = True
ieApp.Navigate = "<url here; sorry, its confidential>"
Do While ieApp.Busy And Not ieApp.ReadyState = READYSTATE_COMPLETE
DoEvents
Loop
Dim ieElement As Object
Set ieElement = ieApp.Document.getElementById("i_specialist")
ieElement.Value = "TestValue"
The error points to:
Set ieElement = ieApp.Document.getElementById("i_specialist")
I really have no idea what went wrong. I'm thinking two possible causes:
- Object type is wrong
- Something went wrong with loading the page that the code can't find the field
Any help is appreciated! Thanks!
did you checked in the html document page that an html element with the id i_specialist is exist?
anyway when im working with htmlElements im doing it like this.. worth to give it a try...
Set ie = CreateObject("InternetExplorer.Application")
With ie
.Visible = True
.Navigate "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
Do Until .ReadyState = 4
DoEvents
Loop
.document.all.Item("i_specialist").Value = "TestValue"
End With
Related
I'm trying to populate this form (https://help.grab.com/merchant/vi-vn/360027910731-DJang-ky-tham-gia-chuong-trinh-khuyen-mai-cung-GrabFood) with a set of excel data, filling each field of the form with respective column in Excel. I came across several tutorials on StackOverflow and Youtube on using VBA to open IE, navigate and fill in text box, from which I wrote these codes.
The problem comes when I run this code and Excel returns an error message box saying
Run-time Error '-2147467259 (80004005) Automation Error Unspecified Error.
I am too amateur to diagnose these codes that run perfectly on various videos on Youtube. Hope you guys can help me :)
Sub IE()
Dim IE As InternetExplorerMedium
Set IE = New InternetExplorerMedium
Dim doc As HTMLDocument
Set doc = IE.document //The error I mentioned above is in this line
IE.Visible = True
IE.navigate "https://help.grab.com/merchant/vi-vn/360027910731-DJang-ky-tham-gia-chuong-trinh-khuyen-mai-cung-GrabFood"
Do While IE.Busy
DoEvents
Loop
For Each ele In IE.document.getElementsByClassName("ant-radio-input")
If ele.Value = ThisWorkbook.Sheets("Sheet1").Range("A1") Then ele.Click: Exit For
Next
doc.getElementById("phone").Value = ThisWorkbook.Sheets("Sheet1").Range("C2").Value
doc.getElementById("email").Value = ThisWorkbook.Sheets("Sheet1").Range("D2").Value
IE.Quit
End Sub
You can't set the ie.document until after you have created the IE instance and the document is loaded.
IE.Visible = True
IE.navigate "https://help.grab.com/merchant/vi-vn/360027910731-DJang-ky-tham-gia-chuong-trinh-khuyen-mai-cung-GrabFood"
While IE.Busy Or IE.ReadyState <> 4:DoEvents:Wend
Set doc = IE.document
I'm trying use Excel's IE automation tools to click a website link within a users profile of this site. Using the following in VBA:
ie.Document.getElementsByClassName("website")(0).getElementsByTagName("a")(0).Click
But keep getting the Runtime error '438' when ran. Any advice on how to fix this or if clicking this link is even possible please? Thanks.
EDIT (Full Code):
Dim ie As InternetExplorer
Dim html As HTMLDocument
Set ie = New InternetExplorer
ie.Visible = True
ie.Navigate "site"
Do While ie.READYSTATE <> READYSTATE_COMPLETE
DoEvents
Loop
Set objA = ie.Document.getElementsByClassName("website")(0) 'GETTIN ERROR HERE
objA.getElementsByTagName("a")(0).Click
End Sub
It would appear that there were a few minor issues here.
One being that .Click doesn't always function properly, I would suggest using .getAttribute("href") combined with ie.Navigate()
Another being that you seem to define html then never use it again.
The following code works:
Sub test()
Dim ie As InternetExplorer
Dim html As HTMLDocument
Set ie = New InternetExplorer
ie.Visible = True
ie.Navigate "http://beverlyhills.yourkwoffice.com/mcj/user/AssociateSearchSubmitAction.do?orgId=5058&lastName=&firstName=&rows=100"
Do While ie.READYSTATE <> READYSTATE_COMPLETE
DoEvents
Loop
Set html = ie.Document
Set objA = html.getElementsByClassName("website")(0).getElementsByTagName("a")(0)
ie.Navigate (objA.getAttribute("href"))
End Sub
Using Excel VBA I'm trying to get the contents of a specific class from a webpage.
This is the code:
sUrl = "https://www.example.com/"
Set oBrowser = CreateObject("InternetExplorer.Application")
oBrowser.navigate sUrl
With oBrowser
Do While .Busy Or .ReadyState <> 4: Loop
End With
Set HTMLDoc = oBrowser.document.getElementsByClassName("classNew")
This code is creating the IE browser and navigating to the correct page.
However, I get the error:
On line:
Set HTMLDoc = oBrowser.document.getElementsByClassName("classNew")
Compiling the code doesn't produce any error.
You'll need to know the index number of the class element you want, or if its the only element with that class name try:
Set HTMLDoc = oBrowser.document.getElementsByClassName("classNew")(0)
You'll also need .innerText, outerText, innerHTML or outerHTML at the end in order to convert the object into a string.
I am trying to upload a .jpg file to a free online OCR site. I am using Excel VBA for this project:
Sub getOcrText()
Dim ocrAddress As String: ocrAddress = "http://www.free-online-ocr.com"
Dim picFile As String: picFile = "C:\Users\310217955\Documents\pdfdown\test.jpg"
Dim elementCollection As Variant
Dim IE As New InternetExplorerMedium
With IE
.Visible = True
.Navigate (ocrAddress)
Do While IE.Busy: DoEvents: Loop
Set elementCollection = IE.document.getElementsByName("fileUpload")
End With
IE.Quit
Set IE = Nothing
End Sub
However, when I run the code to see whether I get objects to elementCollection I get a Runtime error, automation error, unspecified error, the code successfully navigates to the desired webpage.
How do I overcome this error?
You need to change a couple lines.
First this one:
Dim IE As Object: Set IE = CreateObject("InternetExplorer.Application")
.
The second problem...
IE.Busy is not a sufficient test. Make that line the following instead:
Do While (IE.Busy Or IE.READYSTATE <> 4): DoEvents: Loop
I'm trying to automate a form submission in Excel for work, and In have trouble with the basics. I keep getting the error message:
"Method 'Document' of object 'IWebBrowser2' failed"
With the code as is, and if I include the Or part in the waiting check, I get the error
"Automation Error The object invoked has disconnected from its clients."
I'm not sure what to do here, I've searched all over for solutions. This code is intended to eventually do more than this, but it keeps failing on the first try to getElementsByTagName.
Sub GoToWebsiteTest()
Dim appIE As Object 'Internet Explorer
Set appIE = Nothing
Dim objElement As Object
Dim objCollection As Object
If appIE Is Nothing Then Set appIE = CreateObject("InternetExplorer.Application")
sURL = *link*
With appIE
.Visible = True
.Navigate sURL
End With
Do While appIE.Busy ' Or appIE.ReadyState <> 4
DoEvents
Loop
Set objCollection = appIE.Document.getElementsByTagName("input")
Set appIE = Nothing
End Sub
I ran into this same issue a while back. Use internet explorer at a medium integrity level. InternetExplorer defaults to a low integrity level which, if you are doing this over a local intranet at work, sometimes will give the second error message you show above.
Click here for more reading on this. I've modified your code below. Please let me know if that helps.
Sub GoToWebsiteTest()
Dim appIE As InternetExplorerMedium
'Set appIE = Nothing
Dim objElement As Object
Dim objCollection As Object
Set appIE = New InternetExplorerMedium
sURL = "http://example.com"
With appIE
.Navigate sURL
.Visible = True
End With
Do While appIE.Busy Or appIE.ReadyState <> 4
DoEvents
Loop
Set objCollection = appIE.Document.getElementsByTagName("input")
Set appIE = Nothing
End Sub
Remember references for Microsoft Internet Controls, and depending on what you plan on doing further, Microsoft HTML Object Library
Not exactly same as above code but somehow similar , the following code solved my problem:
Do
Loop Until ie.readystate = 3
Do
Loop Until ie.readystate = 4
Just put it before the line you want to start working with the contents.
To get more information about how does it work you can check here
The below method solved my problem for this error:
Close all the explorer instances through 'Task manager' and try to run the code it will work.