Author: Calvin Smith
http://www.CalvinSmithSoftware.com/codedisk/sneakpeek.htm

The following code demonstrates how a developer can
programmatically write to Excel cells within different
worksheets.


Sub WriteToMultipleExcelSheets()
' -------------------------------------------------------------------------
' Author: Calvin Smith - www.CalvinSmithSoftware.com
' Environment(s): MS Access (32-bit) / Visual Basic (32-bit)
' -------------------------------------------------------------------------
'
'   *****************************************
'   * Courtesy code from my CodeDisk© product
'   *****************************************
   '
   ' ----------------------------------------------------------------------------
   ' Purpose: Example of how to write to Excel cells within different worksheets
   '
   ' Accepts: Nothing
   '
   ' Returns: Nothing
   '
   ' NOTE: Remember to reference the Excel 9.0 Object Library
   ' ----------------------------------------------------------------------------
   '
On Error GoTo ErrorHandling_Err

Dim xlapp As New Excel.Application
Dim xlbook As New Excel.Workbook

Set xlbook = xlapp.Workbooks.Open("C:\Calvin\MyWorkbook.xls")

With xlbook
   'Write to cell A1 in the first sheet
   .Worksheets(1).Range("A1") = "Calvin"
   'Write to cell A1 in the second sheet
   .Worksheets(2).Range("A1") = "Smith"
End With

xlapp.ActiveWorkbook.Save
xlapp.Quit

ErrorHandling_Exit:
   Exit Sub

ErrorHandling_Err:
   If Err Then
       'Trap your error(s) here, if any!
       Resume ErrorHandling_Exit
   End If

End Sub