Excelのブックに、シートを追加する方法を記載します。
シートを1つ追加する
Dim xlApp As Excel.Application = New Excel.Application()
xlApp.Workbooks.Open("C:\work\myBook.xls")
----------------------------------------------------------------------
Dim NewSheet As Excel.Worksheet = xlApp.Worksheets.Add()
NewSheet.Name = "シート1"
または
With xlApp.Worksheets.Add()
.Name = "シート1"
End With
----------------------------------------------------------------------
xlApp.Visible = True
System.Threading.Thread.Sleep(3000)
xlApp.Quit()
System.Runtime.InteropServices.Marshal.ReleaseComObject(NewSheet)
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApp)
シートを複数追加する
xlSheets.Add(Before, After, Count, Type) 'Before:ここで指定したシートの前に新規シートが追加されます。 'After :ここで指定したシートの後ろに新規シートが追加されます。 'Count :追加するシート数です。 'Type :追加するタイプを指定します。通常(WorkSheet)
Dim xlApp As Excel.Application = New Excel.Application()
xlApp.Workbooks.Open("C:\work\myBook.xls")
Dim xlSheet As Excel.Worksheet = DirectCast(xlApp.Worksheets(1), Excel.Worksheet) ' 1シート目を選択
'指定シート(xlSheet)の後ろに2つ追加します。
xlApp.Worksheets.Add(, xlSheet, 2, Excel.XlSheetType.xlWorksheet)
xlApp.Visible = True
System.Threading.Thread.Sleep(3000)
xlApp.Quit()
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlSheet)
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApp)