CHAPTER 9 n ACTIVEX AND .NET 345
Our Save button will do three things:
??? Set up the worksheet by adding headings and adjusting column widths
??? Put the data from the data entry form on the worksheet
??? Close the data entry form
5. Add the following code to the btnSave_Click event:
FormatForm()
PlaceData()
Close()
As you can see, each command maps to one of the three functions that the Save command
will perform. The Close method is a built-in method of the Windows form object.
Let??™s add the code for the FormatForm and PlaceData methods.
6. On the NewEmpForm.vb code module, add a new subroutine and name it FormatForm.
7. Add the following code to the FormatForm subroutine:
DoHeadings()
Dim rng As Excel.Range
With Globals.ThisAddIn.Application
rng = .Range("A5")
rng.Value = "First Name"
rng.Font.Bold = True
rng.ColumnWidth = 15
rng = .Range("B5")
rng.Value = "Mid Init"
rng.Font.Bold = True
rng.ColumnWidth = 15
rng = .Range("C5")
rng.Value = "Last Name"
rng.Font.Bold = True
rng.ColumnWidth = 15
rng = .Range("A8")
rng.Value = "Date of Hire"
rng.Font.Bold = True
rng = .Range("B8")
rng.Value = "Job Title"
rng.Font.Bold = True
rng = .Range("C8")
rng.Value = "Reports To"
rng.Font.Bold = True
End With
rng = Nothing
The DoHeadings method will put the title and subtitle on the worksheet. The repeated reference
to the rng variable sets the active cell, formats it, and places any text labels in the cell.
CHAPTER 9 n ACTIVEX AND .NET 346
nNote We have a reference to the Visual Basic Globals module in our With block.
Pages:
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317