none
Adding a second EXcel worksheet via VB.net RRS feed

  • Question

  • I am looking for an example adding a second worksheet to an Excel Workbook using VB.net.
    Monday, January 27, 2020 2:56 PM

All replies

  • Hi,

    Here's a sample:
    Dim xlApp As New Microsoft.Office.Interop.Excel.Application
    Dim xlSht As New Microsoft.Office.Interop.Excel.Worksheet
    ' ---
    With xlApp
    	.Workbooks.Open("G:\Excel files\Book1.xlsx")
    	.Worksheets.Add()
    	.ActiveSheet.Name = "New Sheet"
    End With
    ' --- 
    xlApp.Visible = True
    
    'System.Threading.Thread.Sleep(3000)
    'xlApp.Quit()
    'System.Runtime.InteropServices.Marshal.ReleaseComObject(xlSht)
    'System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApp)
    You need to add an Excel Object Library in your project - [References]:
    (Microsoft.Office.Interop.Excel.dll)
    The left side of a screenshot:


    The right side of a screenshot:


    Regards,

    Ashidacchi -- http://hokusosha.com

    • Edited by Ashidacchi Tuesday, January 28, 2020 12:02 AM
    Monday, January 27, 2020 11:54 PM