Web Automation - Retrieve company Names - Ticker

     

  • Through this web automation we can retrieve company names from Yahoo web to excel workbook, by inserting symbols in search box.
  •  

  • Click on image to view the video
  • Some portion of code changed according to the changes happened in underlying website
  •  

     

    Download The Workbook

    Sub Update_Ticker_In_Searchbox_and_Retrieve_CompanyName_MultipleExplorers()
    'Find the max value to run the loop based on Number of tickers
    Dim sh As Worksheet
    Set sh = ThisWorkbook.Sheets("Yahoo_All Elements")
    MaxRow = sh.Range("A" & Rows.Count).End(xlUp).Row
    sh.Range(Cells(2, 2), Cells(sh.UsedRange.Rows.Count + 2, 2)).ClearContents
    'Creating Object for Internet Explorer
    Dim IE As InternetExplorer
    r = 2 ' As ticker symbols starts from 2nd row

    'Run the Loop until the blank cell hits in COLUMN "A"
    Do Until sh.Range("A" & r).Value = ""
    Set IE = New InternetExplorer
    IE.Visible = True
    IE.navigate "https://finance.yahoo.com/"
    Application.Wait (Now + TimeValue("00.00.06"))
    Ticker = sh.Range("A" & r).Value
    Set doc = IE.document
    IE.document.getElementsByTagName("input")("yfin-usr-qry").Value = Ticker
    IE.document.getElementById("header-desktop-search-button").Click
    Application.Wait (Now + TimeValue("00.00.05"))
    'Retrieve all the elements based on CLASS NAME
    Set Cnames = IE.document.getElementsByClassName("D(ib) Fz(18px)")
    For Each Cname In Cnames
    sh.Cells(r, 2).Value = Cname.innerText
    sh.Columns(2).AutoFit
    r = r + 1
    Next
    IE.Quit
    Set IE = Nothing
    Loop

    MsgBox "Hi Process Completed"

    End Sub