i am trying this
Sub JJ()
Dim IE As New SHDocVw.InternetExplorer
Dim hdoc As MSHTML.HTMLDocument
Dim ha As String
IE.Visible = True
IE.navigate "https://www.nseindia.com/get-quotes/equity?symbol=DIVISLAB"
Do While IE.readyState <> READYSTATE_COMPLETE
Loop
Set hdoc = IE.document
ha = hdoc.getElementById("preOpenFp").innerText
Debug.Print ha
End Sub
Please suggest any solution for that.
the point is in image.
If you want to read the data from the Pre-Open Markt you have to change the url as follows https://www.nseindia.com/get-quotes/equity?symbol=DIVISLAB#info-preopenmkt.Try this code.
Sub JJ()
Dim IE
Set IE = CreateObject("InternetExplorer.Application")
'Dim IE As New SHDocVw.InternetExplorer
Dim hdoc As MSHTML.HTMLDocument
Dim ha As String
IE.Visible = True
IE.navigate "https://www.nseindia.com/get-quotes/equity?symbol=DIVISLAB#info-preopenmkt"
Do While IE.Busy: DoEvents: Loop
Do While IE.Busy And Not IE.readyState = READYSTATE_COMPLETE: DoEvents: Loop
'Application.Wait (Now + TimeValue("0:00:15"))
Set hdoc = IE.document
ha = hdoc.getElementById("preOpenIep").innerText
Debug.Print (ha)
End Sub
Related
I want to create a list of player names scraping a website. The Internet Explorer starts but I get an run time error "438" - Object does not support this property or method.
Structure of webpage
My coding is as follows:
Option Explicit
Sub Kickbase()
Dim IE As New SHDocVw.InternetExplorer
Dim HTMLdoc As MSHTML.HTMLDocument
Dim HTMLPlayers As MSHTML.IHTMLElementCollection
Dim HTMLPlayer As MSHTML.IHTMLElement
Dim i As Integer
Dim HTMLfirstName As Object
Dim firstName As String
IE.Visible = True
IE.Navigate "https://play.kickbase.com/transfermarkt/kaufen"
Do While IE.ReadyState <> READYSTATE_COMPLETE
Loop
Application.Wait (Now + TimeValue("0:00:10"))
Set HTMLdoc = IE.Document
Set HTMLPlayers = HTMLdoc.getElementsByClassName("players")
For i = 0 To HTMLPlayers(0).getElementsByClassName("firstName").Length - 1
Set HTMLfirstName = HTMLPlayers(0).getElementsByClassName("firstName")
If Not HTMLfirstName Is Nothing Then
firstName = Trim(HTMLfirstName.innerText)
Else
firstName = "no_value"
End If
Debug.Print firstName
Next i
End Sub
I have activated the following libraries:
Since it's not possible to test the website on my own, the code below might not be the best way to do it but it should work:
Sub Kickbase()
Dim IE As New SHDocVw.InternetExplorer
Dim HTMLdoc As MSHTML.HTMLDocument
Dim HTMLPlayers As Object
Dim i As Integer
Dim firstName As String
IE.Visible = True
IE.navigate "https://play.kickbase.com/transfermarkt/kaufen"
Do While IE.readyState <> READYSTATE_COMPLETE
DoEvents
Loop
Application.Wait (Now + TimeValue("0:00:10"))
Set HTMLdoc = IE.document
Set HTMLPlayers = HTMLdoc.getElementsByClassName("playerName")
For i = 0 To HTMLPlayers(0).getElementsByClassName("firstName").Length - 1
firstName = Trim$(HTMLPlayers(0).getElementsByClassName("firstName")(i).innerText)
If firstName = vbNullString Then firstName = "no_value"
Debug.Print firstName
Next i
'=== Optional depending on your use case, remember to close IE or else it will remain there ===
'IE.Quit
'Set IE = Nothing
End Sub
I need to switch from ie to xmhttp60, and get the result of the execScript. Is there any way to do it? Below the code
I'm using.
Sub MostrarMasButton()
Dim ie As InternetExplorer
Dim CurrentWindow As HTMLWindowProxy
url = "https://es.investing.com/equities/amazon-com-inc-earnings"
Set ie = New InternetExplorer
ie.Visible = True
ie.navigate url
Do While ie.Busy = True Or ie.readyState <> 4: DoEvents: Loop
ie.document.parentWindow.execScript ("showMoreEarningsHistory(6435, this)")
End Sub
I am trying to download some data from website which starts download upon clicking.
But this code is not working, Can anyone help.
Dim ie As InternetExplorer
Dim htmldoc As MSHTML.IHTMLDocument
Dim HTMLInput As MSHTML.IHTMLElementCollection
Dim HTMLAs As MSHTML.IHTMLElementCollection
Dim HTMLA As MSHTML.IHTMLElement
Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = True
'Navigate to webpage
Dim ieURL As String: ieURL = "http://erldc.org/final-schedule.aspx"
ie.navigate ieURL
Do While ie.readyState <> READYSTATE_COMPLETE
Loop
Set htmldoc = ie.document
Set HTMLInput = htmldoc.getElementsByTagName("a")
For Each HTMLA In HTMLAs
Debug.Print HTMLA.getAttribute("classname"), HTMLA.getAttribute("href"), HTMLA.getAttribute("rel")
If HTMLA.getAttribute("href") = "javascript:__doPostBack('ctl00$ContentPlaceHolder1$Calendar1','6420')" Then
HTMLA.Click
Exit For
End If
Next HTMLA
End Sub
Try pausing the macro for a few seconds, maybe 5 seconds, after the Do While/Loop that checks for the ReadyState...
Dim sngFinish As Single
Dim intPauseTime As Integer
intPauseTime = 5 'in seconds
sngFinish = timer + intPauseTime
Do While timer < sngFinish
DoEvents
Loop
Also, I would suggest that you check the Busy state of Internet Explorer, in addition to the ReadyState, and add DoEvents...
Do While ie.Busy Or ie.readyState <> READYSTATE_COMPLETE
DoEvents
Loop
Hope this helps!
My code :
Sub login()
Dim IE As Object
Dim HTMLDoc As Object, HTMLDoc2 As Object
Dim objCollection As Object
Const navOpenInNewTab = &H800
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
IE.Navigate "https:/com/1/19/login.esp"
Do While IE.Busy Or IE.ReadyState <> 4: Loop
Set HTMLDoc = IE.Document
With HTMLDoc
HTMLDoc.getElementById("USERNAME").Value = "xxxx" 'Entering credential
HTMLDoc.getElementById("PASSWORD").Value = "yyyyy"
End With
Set objCollection = IE.Document.getElementById("loginbutton")
objCollection.Click
'Second webpage
Do While IE.Busy Or IE.ReadyState <> 4: Loop ' opening the second webpage
Set HTMLDoc2 = IE.Document
With HTMLDoc2
**HTMLDoc2.getElementById("DEPARTMENTID").selectedindex = 1 'Drop down menu
HTMLDoc2.getElementById("DEPARTMENTID").FireEvent ("onchange")**
End With
Set objCollection = IE.Document.getElementById("loginbutton")
objCollection.Click
End Sub
Q)What code changes do I do to select Dwell_DF option Value 1567?
The above code gives run time error '424' : Object required.
HTMLDoc2.getElementById("DEPARTMENTID").selectedindex = 1 'Drop down menu
HTMLDoc2.getElementById("DEPARTMENTID").FireEvent ("onchange")
The above line give the error.
In the first webpage I fill the login credentials then in the next page is that of the image pasted with this post. Here I want to change the value in the drop down menu.
Give this a try. The value "1567" corresponds with the InnerText "Dwell_DF".
With HTMLDoc2
.getElementById("DEPARTMENTID").Focus
.getElementById("DEPARTMENTID").Value = "1567" 'You can also loop to find the text of the Option
.getElementById("DEPARTMENTID").FireEvent ("onchange")
End With
It should be something like this.
Sub passValueToComboBox1()
Dim ie As Object
Dim oHTML_Element As IHTMLElement
Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = True
ie.navigate "http://your_URL_here.php"
While ie.Busy Or ie.readyState <> 4: DoEvents: Wend
Set oHTML_Element = ie.document.getElementsByName("selectedReportClass")(0)
If Not oHTML_Element Is Nothing Then oHTML_Element.Value = "FUBU7"
For Each oHTML_Element In ie.document.getElementsByTagName("input")
If oHTML_Element.Type = "submit" Then oHTML_Element.Click: Exit For
Next
End Sub
Check out the link below for some other ideas of how to programatically interact with a web site.
http://vbadud.blogspot.com/2009/08/how-to-login-to-website-using-vba.html
This is not for the first time I am mentioning this...but yeah I am a rookie in vba and in need of help...
I am having trouble in filling up a value in a box in webpage using vba excel.
The source code of the box is
<input
name="MultiRenameTable_OR:wt.epm.EPMDocument:3053059700_NEWNAME_JSID"
class="enabledfield"
id="MultiRenameTable_OR:wt.epm.EPMDocument:3053059700_NEWNAME_JSID"
style="WIDTH:98% onblur="setJSAttributeValue(this,'NEWNAME_JSID','MultiRenameTable', 'epmdoc_09876889_u46_drw',undefined)" type="text" size="25" ?=""
trlId="MultiRenameTable_epmdoc_09876889_u46_drw_NEWNAME_JSID"></input>
the code i wrote is
Sub xx()
Dim ie As Object
Dim doc As HTMLDocument
Dim lo As IHTMLElementCollection
Dim l As IHTMLElement
Set ie = CreateObject("internetexplorer.application")
ie.navigate "mysiteurl"
ie.Visible = True
Do While ie.Busy: DoEvents: Loop
Do While ie.readyState <> 4: DoEvents: Loop
Set doc = ie.document
doc.getElementById("MultiRenameTable_OR:wt.epm.EPMDocument3053059700_NEWNAME_JSID").Value = "xyz"
End Sub
It doesnt set the value.
Also i cannot use "name","ID","trlID","onblur" because they keep on changing each time i launch IE.
Please help me with this.
I'm guessing from the setJSAttributeValue that the name will always contain the substring "NEWNAME_JSID". Just grab all of the input elements, then loop through them looking for it in the name:
Sub xx()
Dim ie As Object
Dim doc As HTMLDocument
Dim lo As IHTMLElementCollection
Dim l As IHTMLElement
Set ie = CreateObject("internetexplorer.application")
ie.navigate "mysiteurl"
ie.Visible = True
Do While ie.Busy: DoEvents: Loop
Do While ie.readyState <> 4: DoEvents: Loop
Set doc = ie.document
Set lo = doc.getElementsByTagName("input")
For Each l In lo
If l.Name Like "*NEWNAME_JSID*" Then
'Do whatever.
Exit For
End If
Next l
End Sub