Click here to Skip to main content
15,918,742 members
Home / Discussions / COM
   

COM

 
GeneralError firing callback event Pin
Mayur Mahajan19-Feb-05 19:03
Mayur Mahajan19-Feb-05 19:03 
GeneralIPropertyBag Pin
nsrsetty18-Feb-05 18:33
nsrsetty18-Feb-05 18:33 
GeneralCOM Service Pin
Vinicius Pontes18-Feb-05 0:04
Vinicius Pontes18-Feb-05 0:04 
GeneralRe: COM Service Pin
ThatsAlok19-Feb-05 6:04
ThatsAlok19-Feb-05 6:04 
GeneralRe: COM Service Pin
Vinicius Pontes20-Feb-05 23:38
Vinicius Pontes20-Feb-05 23:38 
GeneralRe: COM Service Pin
ThatsAlok21-Feb-05 0:38
ThatsAlok21-Feb-05 0:38 
GeneralCreate a new Thread Pin
BEamer17-Feb-05 2:25
BEamer17-Feb-05 2:25 
GeneralExcel COM Pin
MJWhiteman217-Feb-05 0:44
MJWhiteman217-Feb-05 0:44 
I'm trying to use some Excel COM from Visual C++, but am having difficulty calling certain functions. For example, take the WorkSheets.Add method. The function declaration is as follows:

LPDISPATCH Add(const VARIANT& Before, const VARIANT& After, const VARIANT& Count, const VARIANT& Type);

By looking in the Excel VBA Help, I can get documentation for this method:

Add Method (Worksheets Collection)

Creates a new worksheet. The new worksheet becomes the active sheet. Returns a Worksheet object.

Syntax

expression.Add(Before, After, Count, Type)

expression Required. An expression that returns a Worksheets object.

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. The default value is one.

Type Optional Variant. The sheet type. Can be one of the following XlSheetType constants: xlWorksheet, xlExcel4MacroSheet, or xlExcel4IntlMacroSheet. The default value is xlWorksheet.

Remarks

If Before and After are both omitted, the new sheet is inserted before the active sheet.


OK, now for some example code. I can add a new worksheet quite easily using the following code:

// After obtaining a Worksheets object, called ws:<br />
COleVariant VOptional((long)DISP_E_PARAMNOTFOUND, VT_ERROR);<br />
ws.Add(VOptional, VOptional, VOptional, VOptional


The problem is that this default usage inserts the sheet before all current sheets in my workbook, but I want to insert it after all the other sheets. In Excel VBA, I can do this by simply running:

Worksheets.Add.Move after:=Worksheets(Worksheets.Count)

However, I'm having real trouble finding what the data type of the 'After' argument needs to be in C++ and I can't find any sample code anywhere! I have found hundreds of examples passing numbers or strings, but not objects! Can anyone supply some sample code?

Using the _Worksheet.Move method would also accomplish the same thing, but I have the same problem, so any help would be greatly appreciated!
GeneralRe: Excel COM Pin
MJWhiteman217-Feb-05 3:27
MJWhiteman217-Feb-05 3:27 
GeneralInterprocess communication Pin
ravishanker16-Feb-05 17:17
ravishanker16-Feb-05 17:17 
GeneralMSComm32 dependances Pin
Trankil16-Feb-05 6:26
Trankil16-Feb-05 6:26 
GeneralRe: MSComm32 dependances Pin
rwestgraham16-Feb-05 16:43
rwestgraham16-Feb-05 16:43 
QuestionWho have the SkinCrafter dll ? Pin
rushing15-Feb-05 22:16
rushing15-Feb-05 22:16 
Generalrestore IXMLDOMElement from pointer Pin
Konrad Windszus15-Feb-05 1:18
Konrad Windszus15-Feb-05 1:18 
GeneralMS word Pin
merlinos14-Feb-05 14:43
merlinos14-Feb-05 14:43 
GeneralIDTExtensbility2 add-in deployment Pin
m6reid14-Feb-05 11:10
sussm6reid14-Feb-05 11:10 
GeneralRe: IDTExtensbility2 add-in deployment Pin
vishalmore21-Feb-05 18:52
vishalmore21-Feb-05 18:52 
GeneralMS Office docs Pin
Chna12-Feb-05 20:57
Chna12-Feb-05 20:57 
GeneralRe: MS Office docs Pin
vishalmore13-Feb-05 20:49
vishalmore13-Feb-05 20:49 
Generalerror in createProcessinginstruction Pin
cj_rahul10-Feb-05 22:19
cj_rahul10-Feb-05 22:19 
GeneralEmbedded Pin
Jnewg59-Feb-05 5:33
Jnewg59-Feb-05 5:33 
GeneralRe: MailItem Interface Problem in Outllok Pin
Jnewg59-Feb-05 5:43
Jnewg59-Feb-05 5:43 
Generalimporting/exporting data from c++ to excel Pin
itsh118-Feb-05 5:43
itsh118-Feb-05 5:43 
GeneralSimple Basic, tricky C++ Pin
AttaTroll7-Feb-05 11:36
AttaTroll7-Feb-05 11:36 
GeneralRe: Simple Basic, tricky C++ Pin
Anonymous8-Feb-05 3:17
Anonymous8-Feb-05 3:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.