I am trying to add sheets using: ThisWorkbook.Sheets.Add
I am able to add one sheet but when I try to add two sheets it give me an error: Application defined or object defined error.
Here is the code to adding sheets:
Application.ScreenUpdating = False
Dim ws As Worksheet
Set ws = ThisWorkbook.Sheets.Add(after:=Worksheets(Worksheets.Count), Count:=2, Type:="C:\Users\TestUser\Desktop\TestWorksheet.xltm")
Set ws = Nothing
Application.ScreenUpdating = True
When I change the Count:=1 it works fine, it displays error for Count:=2
Thanks in advance
The “Count” will only work when you are trying to add xlWorksheet (Which is by default), xlChart, xlExcel4MacroSheet, or xlExcel4IntlMacroSheet.
For example
Even if you don’t include xlWorksheet, it is ok as it is taken by default.
When you are adding from a template you have to do it in a loop. For example