Link to home
Start Free TrialLog in
Avatar of norbs101
norbs101Flag for United States of America

asked on

excel worksheets.add xlchart

I am trying to create a new worksheet of type xlChart (-4109) using the Excel COM interface.
 
The .add method allows me to add 3/4 types of sheets.

     xlDialogSheet = -4116
     xlExcel4IntlMacroSheet = 4
     xlExcel4MacroSheet = 3
     xlWorksheet = -4167

But the com interface throws an error when I try to create the  xlChart (xlChart = -4109) type.

Any suggestions on creating a xlChart type sheet in code?
ASKER CERTIFIED SOLUTION
Avatar of Rory Archibald
Rory Archibald
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
See below code for 2 other options which can be underlined by any com code


Sub AddNewChart()
Dim x As Variant
Set x = ThisWorkbook.Sheets.Add(Type:=xlChart)
x.Name = "NewChart"
Set x = ThisWorkbook.Charts.Add
x.Name = "NewChart1"

End Sub

Open in new window

Avatar of norbs101

ASKER

The Charts.Add method worked perfectly!

Thank you.