How to use input box data?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • C Diemert
    New Member
    • Jan 2011
    • 2

    How to use input box data?

    I have recorded a macro that will use a web query to obtain the latest price of the microsoft (msft) stock. I want to use this macro to get data on other stocks. My thought is to use an input box that asks me to type in the ticker name. The macro will then use this input to obtain the latest price of whatever ticker i type in. I can't figure out how to put the input box data into the macro. In the macro below, I want to put X wherever the web query uses the ticker msft. My plan is to add a bunch of web queries to the macro so when I type in the ticker name into the input box, the macro will return financial sheets, rations, etc:

    Sub Getquote()
    '
    ' Getquote Macro
    ' Macro recorded 1/8/2011 by CLAY D
    '
    ' Keyboard Shortcut: Ctrl+q
    '

    X = InputBox("enter ticker", "ticker name")

    With ActiveSheet.Que ryTables.Add(Co nnection:= _
    "URL;http://finance.yahoo.c om/q?s=msft", Destination:=Ra nge("F27"))
    .Name = "q?s=msft_1 "
    .FieldNames = True
    .RowNumbers = False
    .FillAdjacentFo rmulas = False
    .PreserveFormat ting = True
    .RefreshOnFileO pen = False
    .BackgroundQuer y = True
    .RefreshStyle = xlInsertDeleteC ells
    .SavePassword = False
    .SaveData = True
    .AdjustColumnWi dth = True
    .RefreshPeriod = 0
    .WebSelectionTy pe = xlSpecifiedTabl es
    .WebFormatting = xlWebFormatting None
    .WebTables = """table1"" "
    .WebPreFormatte dTextToColumns = True
    .WebConsecutive DelimitersAsOne = True
    .WebSingleBlock TextImport = False
    .WebDisableDate Recognition = False
    .WebDisableRedi rections = False
    .Refresh BackgroundQuery :=False
    End With
    End Sub
  • David Gluth
    New Member
    • Oct 2010
    • 46

    #2
    I am not familiar with the web site you are querying so don't know the difference between the two msft references that I see in your code, however to include X this is how you would do it:

    "URL;http://finance.yahoo.com/q?s=msft", Destination:=Ra nge("F27"))
    .Name = "q?s=msft_1"

    "URL;http://finance.yahoo.c om/q?s=" & X, Destination:=Ra nge("F27"))
    .Name = "q?s=" & X " & "_1"

    Comment

    Working...