excel.h - How To? Add a new worksheet c++

J

Jona

Hi, I'm trying to create new Worksheets in my code but I really have
no clue how to...
here is part of my code.
the code I'm is really the one from this webpage: http://support.microsoft.com/kb/178781
but the problem is that they say nothing about creating a new
Worksheet.

Thanks for your help in advance.

//Header declarations..
_Application xlApp;
Workbooks wb;
_Workbook _wb;
Worksheets ws;


//Source
//Add Workbook
wb = xlApp.GetWorkbooks();
_wb = wb.Add(covOptional);
ws = _wb.GetSheets();


//Remove the 3 default sheets
_Worksheet selSheet;
selSheet = ws.GetItem(COleVariant((short)1));
selSheet.Delete();
selSheet = ws.GetItem(COleVariant((short)2));
selSheet.Delete();
selSheet = ws.GetItem(COleVariant((short)3));
selSheet.Delete();


If you want to rename any of these sheets is really easy//
selSheet = ws.GetItem(COleVariant((short)2));
selSheet.SetName("NonInteractive Mode Results");


-Jona
 
P

puppet_sock

Hi, I'm trying to create new Worksheets in my code but I really have
no clue how to...
[snip]

For the greater majority of Excel actions, you can find out how
to do them in VB through the Macro Recorder. Turn it on, do the
action manually, turn it off, then look at the code that Excel
created. If you need options, you can usually look them up
pretty easily in the Helps, once you have the hint that the
Macro Recorder gives you. So start with Tools > Macro >
Record New Macro...
Socks
 
J

Jona

Thanks, for the tip. I've tried that and it did give me a hint but
I'm still stuck with the add() function.

I really don't know what to put into this function... any ideas?
thanks!

this are the parameter that the add() function takes:

ws.Add( const VARIANT &Before, const VARIANT &After, const VARIANT
&Count, const VARIANT &Type );
 
M

M. Authement

This is from Excel VBA help:

Before Optional Variant. An object that specifies the sheet before which
the new sheet is added.
After Optional Variant. An object that specifies the sheet after
which the new sheet is added.
Count Optional Variant. The number of sheets to be added. Teh default
value is one.
Type Optoinal Variant. Specifies sheet type. Can be on of the
following XlSheetType constants: xlWorksheet, xlChart, xlExcel4MacroSheet,
or xlExcel4IntlMacroSheet. If you are inserting a sheet based on an
existing template, specify the path to the template. The default value is
xlWorksheet.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top