Hi Guys,
I am new to this so be patient. I am looking to create a button that pulls data from a website based on the content of a cell. I have attempted to use the macro recorder to copy the content of a cell, run a web query (to: http://www.financialpost.com/) and paste the copied cell value into the stock quote search box on the right hand side. I want it to select the ticker, go to financials and import the balance sheet to cell B15. Ideally, I would want it to import all the financials for that ticker (balance sheet, cash flow, income statement) and import it on the sheet with the data side by side.
I have run in to two problems:
1. I can get it to run the macro, but regardless of the content of the copied cell (the ticker), it will only return data from the ticker i used to create the macro.
2. If i click the button more than once, instead of clearing data from the earlier search it will return data next to the earlier data. I would prefer if it wiped the previous search and returned the data in B15.
Ultimately, my goal is to be able to input a ticker in a specific cell, press the "run" button, and have the income statement, cash flow statement, and balance sheet statement data pop up on my "Data" sheet.
This is my code at the moment:
Thanks in advance,
gger.
I am new to this so be patient. I am looking to create a button that pulls data from a website based on the content of a cell. I have attempted to use the macro recorder to copy the content of a cell, run a web query (to: http://www.financialpost.com/) and paste the copied cell value into the stock quote search box on the right hand side. I want it to select the ticker, go to financials and import the balance sheet to cell B15. Ideally, I would want it to import all the financials for that ticker (balance sheet, cash flow, income statement) and import it on the sheet with the data side by side.
I have run in to two problems:
1. I can get it to run the macro, but regardless of the content of the copied cell (the ticker), it will only return data from the ticker i used to create the macro.
2. If i click the button more than once, instead of clearing data from the earlier search it will return data next to the earlier data. I would prefer if it wiped the previous search and returned the data in B15.
Ultimately, my goal is to be able to input a ticker in a specific cell, press the "run" button, and have the income statement, cash flow statement, and balance sheet statement data pop up on my "Data" sheet.
This is my code at the moment:
Any thoughts?Private Sub CommandButton1_Click()
'
' Macro5 Macro
' Macro recorded 05/01/2011 by gger
'
'
Range("B7").Select
ActiveCell.FormulaR1C1 = "AAPL"
Range("D14").Select
With ActiveSheet.QueryTables.Add(Connection:= _
"URL;http://idms.financialpost.com/stocks/balance_sheet.idms?SYMBOL=AAPL&ID_NOTATION=253929" _
, Destination:=Range("D14"))
.Name = "balance_sheet.idms?SYMBOL=AAPL&ID_NOTATION=253929"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlSpecifiedTables
.WebFormatting = xlWebFormattingNone
.WebTables = """IDMS_BalanceSheet"""
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
End Sub
Thanks in advance,
gger.