0

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))
4

2 回答 2

1

The correct syntax to get what you want (in VBA) is:

Sheets.Add After:=Sheets("sheet1")
ActiveSheet.Name = "secondSheet"

I always have better luck creating the sheet in the right position first, then renaming it.

于 2013-07-01T17:53:40.827 回答
0

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
于 2013-07-01T18:09:55.517 回答