Download from web
Code for Google Search
Open Required Webpage
Private Sub CommandButton1_Click()
Dim ie As InternetExplorer
Set ie = New InternetExplorer
ie.Visible = True
ie.navigate "https://in.finance.yahoo.com"
End Sub
Capture the Pricing Data - Single company
Private Sub CommandButton1_Click()
Dim ie As InternetExplorer
Set ie = New InternetExplorer
Dim ticker As String
ticker = Sheets("Sheet2").Range("A2").Value
ie.Visible = True
ie.navigate "https://in.finance.yahoo.com/q?s=" & ticker
Dim doc As HTMLDocument
Do While ie.readyState <> READYSTATE_COMPLETE
'Do Until ie.readyState = READYSTATE_COMPLETE
Set doc = ie.document
Loop
On Error Resume Next
Sheets("Sheet2").Range("B2").Value = doc.getElementById("yfs_l84_" & ticker).innerText
MsgBox "hi pricing updated"
ie.Quit
End Sub
Capture the Pricing Data - Multiple Companies
Private Sub CommandButton1_Click()
Dim max As Integer
max = Range("A1").End(xlDown).Row
Dim ticker As String
For i = 2 To max
ticker = Sheets("Sheet2").Range("A" & i).Value
Dim url As String
url = "http://finance.yahoo.com/d/quotes.csv?s=" & ticker & "&f=nj2f6pd1j1e"
Dim ht As New WinHttpRequest
ht.Open "get", url
ht.Send
result = Split(ht.ResponseText, ",")
Dim parts As Integer
Dim j As Integer
j = 2
For parts = 0 To UBound(result)
Cells(i, j).Value = result(parts)
Columns(j).AutoFit
j = j + 1
Next
UsedRange.WrapText = False
Next
End Sub
Download Tables from YAHOO FINANCE
Private Sub CommandButton1_Click()
Dim qt As QueryTable
Dim url As String
url = "https://in.finance.yahoo.com/q?s=AAPL"
Set qt = QueryTables.Add( _
Connection:="URL;" & url, _
Destination:=Sheets("Sheet1").Range("A1"))
With qt
.Name = "hi"
.WebSelectionType = xlSpecifiedTables
.WebFormatting = xlWebFormattingNone
.WebTables = "2,3"
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableRedirections = True
.FieldNames = True
.RefreshPeriod = 0
.RefreshStyle = xlInsertDeleteCells
.AdjustColumnWidth = True
.Refresh BackgroundQuery:=False
End Sub
Loop through All Elements
For ElementNumber = 0 To Ie.Document.all.Length - 1
If IE.Document.all.Item(ElementNumber).innerText = "Hi" Then
MsgBox IE.Document.all.Item(ElementNumber + 2).Innertext
End If
Next
GetElementsbyTagName - Frame
Set FrameNumbers = ie.document.getElementsByTagName("Frame")
i = 0
For Each FrameNumber In FrameNumbers
Cells(i + 1, 1).Value = FrameNumber.getAttribute("src")
Cells(i + 1, 2).Value = FrameNumber.getAttribute("id")
Cells(i + 1, 3).Value = FrameNumber.Innertext
i = i + 1
Next
GetElementsbyTagName - a
Set Hlinks = ie.document.getElementsByTagName("a")
For Each link In Hlinks
If link.innerText = "Hi" Then
link.Click
Exit For
End If
Next