Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can use <code>InputBox</code> to collect the user's input. After collecting, you can test their input before continuing to execute the code. here's the input/validation example: </p> <pre><code>'-store user input in 'sUserInput' variable Dim sUserInput As String sUserInput = InputBox("Enter Number:", "Collect User Input") 'test input before continuing to validate the input If Not (Len(sUserInput) &gt; 0 And IsNumeric(sUserInput)) Then MsgBox "Input not valid, code aborted.", vbCritical Exit Sub End If </code></pre> <p>Your code can reference the variable by refering to the <code>sUserInput</code> here's a complete version:</p> <pre><code>Sub Macro2() ' ' Macro2 Macro ' ' Keyboard Shortcut: Ctrl+r ' '-store user input in 'sUserInput' variable Dim sUserInput As String sUserInput = InputBox("Enter Number:", "Collect User Input") 'test input before continuing to validate the input If Not (Len(sUserInput) &gt; 0 And IsNumeric(sUserInput)) Then MsgBox "Input not valid, code aborted.", vbCritical Exit Sub End If With ActiveSheet.QueryTables.Add(Connection:= _ "URL;http://network.construction.com/reportviewer.aspx?ids=" &amp; sUserInput, _ Destination:=Range("$A$1")) .Name = "reportviewer.aspx?ids=" &amp; sUserInput .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 </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload