SEARCH
0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Prev | Current Page 288 | Next

Jim DeMarco

"Pro Excel 2007 VBA"


Now we are ready for a small bit of client code.
The Client Code
The really neat thing about using custom DLLs to provide functionality is that it lets us use
such a tiny bit of code in our applications.
CHAPTER 9 n ACTIVEX AND .NET 321
On the standard module you just created, add the following code:
Option Explicit
Sub GetNorthwindData()
Dim oNwindData As cExcelNwind
Set oNwindData = New cExcelNwind
oNwindData.PlaceData ThisWorkbook.Sheets("Sheet1"), "Select * From Orders"
oNwindData.PlaceData ThisWorkbook.Sheets("Sheet2"), "Select * From Employees"
Set oNwindData = Nothing
End Sub
That??™s about it. The two lines of code between the Set statements do all the work, with
each line placing the result of its SQL statement on the worksheet referenced. Let??™s run the
code.
1. Return to Excel.
2. Save the file.
3. Open the Macros dialog box by selecting the Developer ribbon ?¤Macros command.
4. Choose GetNorthwindData from the List of macros.
5. Click the Run button.
nCaution As noted earlier, if you are using the compiled DLL that comes with the source code for this
book, you must create the path C:\ExampleDBs and place the Northwind 2007 database there.
The result is shown in Figure 9-3. Sheet1 contains the order information and Sheet2 contains
the employee information.
CHAPTER 9 n ACTIVEX AND .NET 322
Figure 9-3. Result of GetNorthwindData macro
6. Save the workbook if you like.
nNote Here??™s one of the comparative advantages of the .NET platform vs.


Pages:
276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300