Exercise 1: Setting up a Data Connection
Out of the box, Microsoft Excel contains numerous features that allow you to connect Excel to external data. For many reporting scenarios it is often possible to use a combination of data connections with lookup formulas and data validation to create surprisingly interactive workbooks without writing any code.
Exercise 1 is designed to allow you to begin exploring a technique for accessing external data in Excel.
Task 1 – Accessing External Data in Excel
- Open a new workbook in Excel
- Click on the Data tab
- In the Get External Data group click From Access
- Open the database named Budget.accdb located at %Office2010DeveloperTrainingKitPath%\Labs\VBA\Source\Database
- Select the Stores table and click OK
- Click OK. Notice that the data appears in a table in Excel.
On the Table Tools Design tab of the ribbon, click on Properties to display the External Data Properties dialog box. Explore some of the properties you can modify.
Figure 1
External Data Properties
Click on the Connection Properties button in the upper right quadrant of the dialog box. This will display the Connection Properties dialog box. Explore some of the connection properties that you can modify.
Figure 2
Connection Properties
- Click on the Definition tab and explore the properties that you can modify.
- Change the value of the Command text from Stores to Accounts.
- Click OK to close the Connection Properties and then click OK again to close the External Data Properties dialog. Notice that Excel displays the Accounts table now.
- On the Table Tools Design tab of the ribbon, click Properties
- Click on the Connection Properties button
- Click on the Definition tab
- Change the Command type to SQL
- Set the Command text to SELECT * FROM [FACTS CROSSTAB]
- WHERE [STORE NAME]='Warehouse District Store'
- AND [FISCAL YEAR]=2009
- Click OK to close the Connection Properties and then click OK again to close the External Data Properties dialog. Observe that Excel displays information from the query you specified.
- Notice that the table functionality in Excel allows you to easily sort and filter the information. For example, click on the drop-down arrow in the Scenario Type column heading.
- Uncheck Budget and click OK. Notice that Excel filters the records for you.
- Close the Workbook, don’t save it.