automating excel 2007

Hi, i have automated excell using VC6++ and my program works. now i need to find the address of the last sell in Column A in excell sheet. please if anyone can help

Val
Last edited on
How are your creating the Worksheets object?
hi, this is a line

objSheets = objBook.GetWorksheets(); // get worksheets


The issue is with your second parameter to the add method. The add method expects a variant with an IDispatch * to the sheet you want to insert the new sheet after, not in the numerical index of the sheet in the worksheets collection.
Last edited on
thanks for the reply,

function GetItem

objSheet = objSheets.GetItem(COleVariant((short)3)); // select worksheet 3

returns LPDISPATCH

but Add, according to definition, is looking for VARIANT

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

so how can I attach or convert LPDISPATCH to VARIANT
1
2
3
4
5
6
7
8
9
VARIANT 	varAfter;
IDispatch 	* pdispSheet;

pdispSheet = objSheets.GetItem(COleVariant((short)3));

varAfter.vt = VT_DISPATCH;
varAfter.pdispVal = pdispSheet;

objSheets.Add(VOptional, varAfter, COleVariant((short)1),VOptional); 
all works!! THANK you so much.
Hi cburn11, thanks again for the help. this also works:

objSheet = objSheets.GetItem(COleVariant((short)3));

varAfter.vt = VT_DISPATCH;
varAfter.pdispVal = objSheet;

objSheet =objSheets.Add(VOptional, varAfter, COleVariant((short)1),VOptional);
Topic archived. No new replies allowed.