Hi,
Dim oExcel As Microsoft.Offic e.Interop.Excel .Application
Dim oBook, oBook1 As Microsoft.Offic e.Interop.Excel .Workbook
Dim oSheet As Microsoft.Offic e.Interop.Excel .Worksheet
'Start a new workbook in Excel.
oExcel = New Microsoft.Offic e.Interop.Excel .Application
oBook = oExcel.Workbook s.Add
oBook1 = oExcel.Workbook s.Add
'Add data to cells of the first worksheet in the new workbook.
oSheet = CType(oBook.Wor ksheets(1),
Microsoft.Offic e.Interop.Excel .Worksheet)
oSheet.Range("A 1").Value = "Last Name"
oSheet.Range("B 1").Value = "First Name"
oSheet.Range("C 1").Value = "Price"
oSheet.Range("A 1:B1").Font.Bol d = True
oSheet.Range("A 2").Value = "Doe"
oSheet.Range("B 2").Value = "John"
oSheet.Range("C 2").Value = 12345.456
oSheet.Range("C 2").Cells.Numbe rFormat = "$0.00"
oSheet = CType(oBook.Wor ksheets(2),
Microsoft.Offic e.Interop.Excel .Worksheet)
oSheet.Range("A 1").Value = "Last Name"
oSheet.Range("B 1").Value = "First Name"
oSheet.Range("C 1").Value = "Price"
oSheet.Range("A 1:B1").Font.Bol d = True
oSheet.Range("A 2").Value = "Doe"
oSheet.Range("B 2").Value = "John"
oSheet.Range("C 2").Value = 12345.456
oSheet.Range("C 2").Cells.Numbe rFormat = "$0.00"
'Save the Workbook and quit Excel.
oExcel.DisplayA lerts = False
oBook.SaveAs("c :\Book1.xls")
oSheet = Nothing
oBook = Nothing
oExcel.Quit()
oExcel = Nothing
GC.Collect()
Ken
-------------------------------------
"KC" <yo*@dontneed.t his> wrote in message
news:e2******** ******@TK2MSFTN GP11.phx.gbl...
Does anybody know how to add a specific number of worksheets to an Excel
spreadsheet through VB.net? I'm trying to export some datatables to an excel
file, but I only want as many sheets in the workbook as there are tables.
Right now the routine I'm tweaking from
http://support.microsoft.com/default...b;EN-US;306022
adds the default, (3).
At this stage I can export data fine, I just don't know how to control the
number sheets.
--
Ken