I have a recorded macro to pull select fields from a web service, the URL is something like http://xxxx.com/reportviewer.aspx?ids=123456789012
I would like to prompt the user to input that number as a variable and have the number be passed to the 2 locations were that number is used in the macro.
I know that i have to create another macro to have the user input a value for after that I’m unsure of how pass that along to be filled in the correct location?
Here is my code so far
Sub Macro2()
'
' Macro2 Macro
'
' Keyboard Shortcut: Ctrl+r
'
With ActiveSheet.QueryTables.Add(Connection:= _
"URL;http://xxxx.com/reportviewer.aspx?ids=123456789012", _
Destination:=Range("$A$1"))
.Name = "reportviewer.aspx?ids=123456789012"
.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 = "30,33,37,38,46"
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
End Sub
Range("A2").Select
You can use
InputBoxto collect the user’s input.After collecting, you can test their input before continuing to execute the code.
here’s the input/validation example:
Your code can reference the variable by refering to the
sUserInputhere’s a complete version: