When you use dynamic parameters, you can use the following three methods to obtain the parameter values:
- Use a dialog box that prompts you to type the values.
- Specify the values to use.
- Get the values from a worksheet cell.
In some of the examples below, you use the Parameters dialog box to make changes to the parameters in a query. Note that these changes do not affect the Web query file you initially use to run the query; any changes you make to the query parameters are stored in the worksheet.
NOTE: Microsoft does not guarantee the examples will work indefinitely.
Example 1: Use the Enter Parameter Value Dialog Box
- Save and close any open workbooks, and then create a new workbook.
- On the Data menu, point to Get External Data, and then click Run Saved Query.
- Click Microsoft Investor Stock Quotes.iqy in the Run Query dialog box, and then click Get Data.
NOTE: The Microsoft Investor Stock Quotes.iqy file is in the Program Files\Microsoft Office\Queries folder. - In the Returning External Data to Microsoft Excel dialog box, click OK.
- In the Enter Parameter Value dialog box, type msft in the box, and then click OK.
Example 2: Specify Cell Values
- Switch to Sheet2 in the workbook, and then type msft in cell A1.
- With A2 selected, point to Get External Data on the Data menu, and then click Run Saved Query.
- Click Microsoft Investor Stock Quotes.iqy in the Run Query dialog box, and then click Get Data.
- In the Returning External Data to Microsoft Excel dialog box, click Parameters.
The Parameters dialog box appears. Notice the option for this Web query uses a prompt for the parameter value. - In the Parameters dialog box, click Get the value from the following cell, click cell A1 to insert the reference =Sheet2!$a$1 in the box, and then click OK.
- Click OK in the Returning External Data to Microsoft Excel dialog box.
A detailed stock quote for Microsoft Corp. (MSFT) is returned to the worksheet. - Change the contents of cell A1 in Sheet2 to a different (valid) stock symbol.
- On the External Data toolbar, click the Refresh Data button.
Example 3: Set Parameter Value
- Switch to Sheet 3 in the workbook, and then type msft in cell A1.
- With A2 selected, point to Get External Data on the Data menu, and then click Run Saved Query.
- Click Microsoft Investor Stock Quotes.iqy in the Run Query dialog box, and then click Get Data.
- In the Returning External Data to Microsoft Excel dialog box, click Parameters.
- In the Parameters dialog box, click Use the following value, type msft in the box, and then click OK.
- In the Returning External Data to Microsoft Excel dialog box, click OK.
A detailed stock quote for Microsoft Corp. (MSFT) is returned to the worksheet. - On the External Data toolbar, click the Refresh Data button.
How to Change the Parameter Value
If you use a specific value for a parameter, as in the previous example, you can change this value in the Parameters dialog box.- Click any cell in the results that are returned to Sheet3.
- On the External Data toolbar, click the Query Parameters button.
- In the Parameters dialog box, change the contents of the Use the following value box to a different stock symbol, and then click OK.
- On the External Data toolbar, click the Refresh Data button.