Home » excel » excel vba – Dynamic Web Query

excel vba – Dynamic Web Query

Posted by: admin May 14, 2020 Leave a comment

Questions:

Go easy on me as I am new at this. I have created a couple of macros that extract search results from:Sec full text search: http://searchwww.sec.gov/EDGARFSClient/jsp/EDGAR_MainAccess.jsp

Now that my data is all cleaned up and set in different columns, I need to create a query based off of the results. In column B I have a list of company names, I would like to reference each cell in column “B”, and query market watch at http://www.marketwatch.com/tools/quotes/lookup.asp?siteID=mktw&Lookup=options+media&Country=us&Type=All for the ticker symbol related to the company name. That would help me out, as eventually I will want to perform multiple queries pulling information about share structure, revenues ect. I would greatly appreciate any time in answering this question.

How to&Answers:

Try below code.

Sub website()

    Dim doc As HTMLDocument
    Dim htmTable As HTMLTable

    Set doc = New HTMLDocument
    With CreateObject("MSXML2.XMLHTTP")
        .Open "GET", "http://www.marketwatch.com/investing/stock/BAC"
        .send
        Do: DoEvents: Loop Until .readyState = 4
        doc.body.innerHTML = .responseText
        .abort
    End With

    Set htmTable = doc.getElementsByClassName("companyname")(0)

    If Not htmTable Is Nothing Then
        MsgBox htmTable.innerText
    End If

     Set htmTable = doc.getElementsByClassName("lastprice")(0)

    If Not htmTable Is Nothing Then
        MsgBox htmTable.innerText
    End If
End Sub