We saw the same reference
earlier in our btnEmail_Click event on our custom task pane object. In order to access objects in an
Excel workbook (or any Office application object), we must go through the Globals module. This module supports
the runtime library members that contain information about the runtime currently being used.
8. Add another subprocedure and name it DoHeadings.
9. Add the following code:
Dim rng As Excel.Range
With Globals.ThisAddIn.Application
rng = .Range("A1")
rng.Value = "HR Data Entry System"
rng.Font.Bold = True
rng.Font.Size = 16
rng = .Range("A2")
rng.Value = "New Employee Information"
rng.Font.Italic = True
rng.Font.Size = 14
End With
rng = Nothing
There??™s nothing new here. This code works exactly like the FormatForm subroutine.
Next, let??™s add the code to put the data on the worksheet.
10. Add a new subroutine, and name it PlaceData.
11. Add the following code:
Dim rng As Excel.Range
With Globals.ThisAddIn.Application
rng = .Range("A6")
rng.Value = Me.txtFName.Text
rng = .Range("B6")
rng.Value = Me.txtMidInit.Text
rng = .Range("C6")
rng.Value = Me.txtLName.Text
rng = .Range("A9")
rng.Value = Me.txtDOH.Text
rng = .Range("B9")
rng.Value = Me.txtTitle.Text
rng = .Range("C9")
rng.Value = Me.txtReportsTo.Text
End With
Again, we??™re not doing anything new here??”we??™re just breaking the functionality up into
smaller pieces.
CHAPTER 9 n ACTIVEX AND .NET 347
The last thing to do is to code the Cancel button.
Pages:
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318