automating excel 2007

Apr 30, 2014 at 1:18pm
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 Jun 10, 2014 at 11:46am
May 1, 2014 at 12:54pm
How are your creating the Worksheets object?
May 1, 2014 at 4:13pm
hi, this is a line

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


May 1, 2014 at 5:03pm
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 May 1, 2014 at 5:03pm
May 1, 2014 at 7:02pm
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
May 1, 2014 at 8:49pm
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); 
May 1, 2014 at 9:05pm
all works!! THANK you so much.
May 2, 2014 at 7:31pm
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.