Apr 30, 2014 at 1:18pm Apr 30, 2014 at 1:18pm UTC
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 Jun 10, 2014 at 11:46am UTC
May 1, 2014 at 12:54pm May 1, 2014 at 12:54pm UTC
How are your creating the Worksheets object?
May 1, 2014 at 4:13pm May 1, 2014 at 4:13pm UTC
hi, this is a line
objSheets = objBook.GetWorksheets(); // get worksheets
May 1, 2014 at 5:03pm May 1, 2014 at 5:03pm UTC
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 5:03pm UTC
May 1, 2014 at 7:02pm May 1, 2014 at 7:02pm UTC
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 9:05pm May 1, 2014 at 9:05pm UTC
all works!! THANK you so much.
May 2, 2014 at 7:31pm May 2, 2014 at 7:31pm UTC
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);