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 298 | Next

Jim DeMarco

"Pro Excel 2007 VBA"

Press Enter, and Visual Studio 2005 will add a complete Try...Catch block for you.
5. Place the insertion point in the first blank line below the Try line of code.
6. Add the following code to set the file name in the data access component and call its
GetData method:
With m_oNWind
.NwindPathFileName = sDB
m_oDS = .GetData("select * from employees")
End With
7. Add the following code to walk through the DataSet and insert the column headings in
the worksheet:
For i = 0 To iCols - 1
m_oSheet.Cells(1, i + 1).Value = ??
m_oDS.Tables("Table1").Columns(i).Caption
Next
8. Place the insertion point in the blank line following the previous code, and press Enter.
CHAPTER 9 n ACTIVEX AND .NET 337
9. Add the following code to walk through the DataSet and insert the employee data on
the worksheet:
row = 2
For Each RowIterator As DataRow In m_oDS.Tables("Table1").Rows
For i = 0 To iCols - 1
m_oSheet.Cells(row, i + 1).Value = ??
RowIterator(m_oDS.Tables("Table1").Columns(i).Caption)
Next
row = row + 1
Next
Next, we??™ll add the code to format the Excel worksheet by applying the AutoFit command
to size each column to show its longest data entry.
10. Place the insertion point in the blank line following the previous code, and press Enter.
11. Add the following code:
Dim r As Excel.Range
m_oSheet.Select()
r = m_oSheet.Range("A1")
r.Select()
Application.Selection.CurrentRegion.Select()
Application.Selection.Columns.AutoFit()
r.Select()
The last thing for us to do is a bit of exception handling.


Pages:
286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310