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
Related
I'm trying to retrieve data from a web page with the following Excel VBA:
Dim HTMLDoc As Object
Dim oBrowser As Object
Sub Website_()
Dim oHTML_Element As Object
Dim sUrl As String
sUrl = "https://www.example.com/"
Set oBrowser = CreateObject("InternetExplorer.Application")
oBrowser.silent = True
'oBrowser.timeout = 60
oBrowser.Navigate sUrl
oBrowser.Visible = False
With oBrowser
Do While .Busy Or .ReadyState <> 4: Loop
End With
Set HTMLDoc = oBrowser.Document.getElementsByClassName("val")
End Sub
This opens MS Edge, not IE, and it is visible.
It returns the error:
Method 'Busy' of object 'IWebBrowser2' failed.
On row:
Do While .Busy Or .ReadyState <> 4
This is on Windows 11, it doesn't have IE, I think. On Windows 10 I have no issues.
Can anyone help?
Thanks in advance!
I would like to search for city in one IE tab then open my generated link in another tab. If I run these operations separately everything work however I am not able to make it work all together. What is possibly wrong?
Debugger points to .Document.getElementsByName("q")(0).Value = "Dublin" saying
Run-time error '-2147467259 (80004005)': Method 'Document' of object
'IWebBrowser 2' failed
Here is my code:
Option Explicit
Sub GetFlightRates()
Dim appIE As Object
Set appIE = CreateObject("internetexplorer.application")
With appIE
.Navigate "https://maps.google.com"
.Document.getElementsByName("q")(0).Value = "Dublin"
.Document.getElementsByClassName("searchbox-searchbutton")(0).Click
.Navigate "https://www.google.co.in/flights/", CLng(2048) '2nd
.Visible = True
End With
Do While appIE.Busy
DoEvents
Loop
'appIE.Quit
Set appIE = Nothing
End Sub
You need a page load wait before attempting to access .document
Option Explicit
Sub OpenTabs()
Dim appIE As Object
Set appIE = CreateObject("internetexplorer.application")
With appIE
.Visible = True
.navigate "https://maps.google.com"
While .Busy Or .readyState < 4: DoEvents: Wend
.document.getElementsByName("q")(0).Value = "Dublin"
.document.getElementsByClassName("searchbox-searchbutton")(0).Click
.navigate "https://www.google.co.in/flights/", CLng(2048) '2nd
While .Busy Or .readyState < 4: DoEvents: Wend
End With
Stop
'appIE.Quit
Set appIE = Nothing
End Sub
I'm trying to auto-complete a form on a website with values of an excel file.
Sub CommandButton1_Click()
Dim IE As Object
Dim objElement As Object
Dim objCollection As Object
Set IE = CreateObject("InternetExplorer.Application")
With IE
.Visible = True
.navigate "https://www.ryanair.com/be/nl/check-in"
End With
Do Until IE.readyState = 4
DoEvents
Loop
IE.document.getElementbyid("username").Value = "resa#connections.be"
End Sub
Thank you for the quick answer! I just made small changes, as I received an error and I work with a button. It works like a charm now!
Public Sub CommandButton1_Click()
Dim ie As New InternetExplorer, t As Date, ele As Object
Const MAX_WAIT_SEC As Long = 10
t = Timer
With ie
.Visible = True
.Navigate2 "https://www.ryanair.com/be/nl/check-in"
While .Busy Or .readyState < 4: DoEvents: Wend
Do
On Error Resume Next
Set ele = .document.getElementById("username")
On Error GoTo 0
If Timer - t > MAX_WAIT_SEC Then Exit Do
Loop While ele Is Nothing
If ele Is Nothing Then Exit Sub
ele.Value = "resa#connections.be"
End With
End Sub
Use a timed loop for element to be present
Option Explicit
'VBE > Tools > References:
' Microsoft Internet Controls
'
Public Sub CommandButton1_Click()
Dim ie As New InternetExplorer, t As Date, ele As Object
Const MAX_WAIT_SEC As Long = 10
With ie
.Visible = True
.Navigate2 "https://www.ryanair.com/be/nl/check-in"
While .Busy Or .readyState < 4: DoEvents: Wend
t = Timer
Do
On Error Resume Next
Set ele = .document.getElementById("username")
On Error GoTo 0
If Timer - t > MAX_WAIT_SEC Then Exit Do
Loop While ele Is Nothing
If ele Is Nothing Then Exit Sub
ele.Value = "resa#connections.be"
Stop
.Quit
End With
End Sub
I have code to open IE, login with username/password, tick some checkboxes, click button and open a report on a pop up window.
I am trying to copy the content of the pop up window to an Excel sheet. The code that deals with the pop up window doesn't detect the url.
Sub MyRosterApps()
Dim MyHTML_Element As IHTMLElement
Dim HTMLdoc As HTMLDocument
Dim MyHTML_Element As IHTMLElement
Dim MyURL As String
Dim objIE As InternetExplorer, t As Date, nodeList As Object, i As Long
Dim ieIEWindow As SHDocVw.InternetExplorer
Dim y As Integer
Const MAX_WAIT_SEC As Long = 5
'Ignore Errors
On Error GoTo Err_Clear
MyURL = "Not a public URL"
Set MyBrowser = New InternetExplorer
MyBrowser.Silent = True
MyBrowser.navigate MyURL
MyBrowser.Visible = True
Do
'Wait till finished
Loop Until MyBrowser.readyState = READYSTATE_COMPLETE
Set HTMLdoc = MyBrowser.document
'Enter user / password
HTMLdoc.all.txtUsername.Value = "username" ' Eneter your email id here
HTMLdoc.all.txtPassword.Value = "password" 'Enter your password here
HTMLdoc.all.Item("btnLogin").Click
For Each MyHTML_Element In HTMLdoc.getElementsByName("btnLogin")
If MyHTML_Element.Type = "submit" Then MyHTML_Element.Click: Exit For
Next
Do
'Wait till finished
Loop Until MyBrowser.readyState = READYSTATE_COMPLETE
Set HTMLdoc = MyBrowser.document
HTMLdoc.all.Item("ucSkillsPicker_lstSkills_35").Click
HTMLdoc.all.Item("btnShowReport").Click
' The Pop Up windows opens
Do
Loop Until MyBrowser.readyState = READYSTATE_COMPLETE
Set HTMLdoc = MyBrowser.document
' Until here is works fine
' Trying to deal with the Pop Up windows
With objIE
.Visible = True
' I am trying to get the active window url which is the pop up
.navigate ieIEWindow.LocationURL
Do While .Busy = True Or .readyState <> 4: DoEvents: Loop
t = Timer
Do
DoEvents
On Error Resume Next
' Go thru DIV classes and find these two oReportCell .a71
Set nodeList = .document.querySelectorAll("#oReportCell .a71")
On Error GoTo 0
If Timer - t > MAX_WAIT_SEC Then Exit Do
Loop While nodeList Is Nothing
If Not nodeList Is Nothing Then
'Paste the value found in DIV classes in Sheet1
With ThisWorkbook.Worksheets("Sheet1")
For i = 0 To nodeList.Length - 1
.Cells(1, i + 1) = nodeList.Item(i).innerText
Next
End With
End If
.Quit
End With
Err_Clear:
If Err <> 0 Then
'Debug.Assert Err = 0
Err.Clear
Resume Next
End If
End Sub
This code below is separate from above. If I run just like this it does what I need. Of course, I have to paste the targeted window url.
.navigate "url of the pop up window"
The issue is that the pop up window url expires or something like that.
After some time the page says that I have to go through selecting some check boxes and submit.
Option Explicit
Public Sub GrabLastNames()
Dim objIE As InternetExplorer, t As Date, nodeList As Object, i As Long
Const MAX_WAIT_SEC As Long = 5
Set objIE = New InternetExplorer
With objIE
.Visible = True
' Paste targeted window. In my case is the pop up window
.navigate "url of the pop up window"
Do While .Busy = True Or .readyState <> 4: DoEvents: Loop
t = Timer
Do
DoEvents
On Error Resume Next
Set nodeList = .document.querySelectorAll("#oReportCell .a71")
On Error GoTo 0
If Timer - t > MAX_WAIT_SEC Then Exit Do
Loop While nodeList Is Nothing
If Not nodeList Is Nothing Then
With ThisWorkbook.Worksheets("Sheet3")
For i = 0 To nodeList.Length - 1
.Cells(1, i + 1) = nodeList.item(i).innerText
Next
End With
End If
.Quit
End With
End Sub
Hello am getting this error while executing the following code
Sub TableExample()
Dim IE As Object
Dim doc As Object
Dim strURL As String
strURL = "http://www.idealo.de/preisvergleich/OffersOfProduct/143513.html"
Set IE = CreateObject("InternetExplorer.Application")
With IE
'.Visible = True
.navigate strURL
Do Until .readyState = 4: DoEvents: Loop
Do While .Busy: DoEvents: Loop
Set doc = IE.document
GetAllTables doc
.Quit
End With
End Sub
The error is getting in this line
Set IE = CreateObject("InternetExplorer.Application")
If I change it to
With CreateObject("WINHTTP.WinHTTPRequest.5.1")
I am using 64bit Windows 7 and office 2010 version
then what should be the code can anyone guide me on this please?