Search code examples
vb.netexcelmove

Move Excel Sheet Using VB.Net


I have an excel sheet with one sheet named "sheet1" and I have added new sheet named "secondsheet" as shown below:

ExcelApp.Worksheets.Add().Name = "secondSheet"

Now how do I move the second sheet to last as it is adding front to the "sheet1"

This is what I have done but unable to move the second sheet

ExcelApp.Worksheets("secondsheet").Move(After:=xlWorkBook.Worksheets(xlWorkBook.Worksheets.Count))

Solution

  • I finally got it solved...There is nothing mistake with the above code but declaring of workbook made me to pull out my hair.

    This is what I have done:

    Dim xlWorkBook As Excel.Workbook
    xlWorkBook = ExcelApp.Workbooks.Add