VBA COUNTA function and C++ automation

D

dk

using the VB TO VC Automation Code Converter (B2CSE utility from Microsoft),
this call to AutoWrap

AutoWrap(DISPATCH_METHOD, &rVal, wkbs1.pdispVal, L"CountA", 1, parm);

sometimes correctly returns the number of non blank values in a range, and
other times it seems to miss values which are in the range, returning 0,
instead
of the number of columns.

Any ideas?


for(int r=1;r<=initialrow;r++)
{

string thecol="";

int acol=25;
thecol=ColumnLetter(acol);

string newrow="";
newrow="A"+biaUtils::extractInt(r)+":"+thecol+biaUtils::extractInt(r);

VARIANT testRange = {0};
VARIANT parm;
VARIANT wkbs;

AutoWrap(DISPATCH_PROPERTYGET|DISPATCH_METHOD, &wkbs, pWorkbook,
L"activesheet", 0);
parm.vt = VT_BSTR;


VARIANT url;
url.vt = VT_BSTR;
int nLen = newrow.size() + 1;
LPWSTR w_filename = new WCHAR [nLen];
mbstowcs(w_filename, newrow.c_str(), nLen);
parm.bstrVal = ::SysAllocString(w_filename);


VARIANT rVal = {0}; // Temporary result holder
VARIANT rVal1 = {0}; // Temporary result holder
AutoWrap(DISPATCH_PROPERTYGET|DISPATCH_METHOD, &rVal, wkbs.pdispVal,
L"range", 1, parm);
VariantClear(&parm);
VariantCopy(&testRange, &rVal);
VariantClear(&rVal);
//VariantClear(&wkbs);


//int rownumber,int endcol
//for(int r=initialrow;r>=1;--r){


VARIANT RangeIsEmpty = {0};
VARIANT RangeIsBlank = {0};
VARIANT wkbs1 ={0};
AutoWrap(DISPATCH_PROPERTYGET|DISPATCH_METHOD, &wkbs1, m_pDispApp ,
L"WorksheetFunction", 0);
VariantCopy(&parm, &testRange);
//AutoWrap(DISPATCH_PROPERTYGET|DISPATCH_METHOD, &rVal, wkbs1.pdispVal,
L"CountA", 1, parm);
AutoWrap(DISPATCH_METHOD, &rVal, wkbs1.pdispVal, L"CountA", 1, parm);
//AutoWrap(DISPATCH_METHOD, &rVal, wkbs1.pdispVal, L"CountIF",
2,_variant_t(""),parm);
AutoWrap(DISPATCH_PROPERTYGET|DISPATCH_METHOD, &rVal1, wkbs1.pdispVal,
L"CountBlank", 1, parm);
//AutoWrap(DISPATCH_METHOD, &rVal1, wkbs1.pdispVal, L"CountBlank", 1,
parm);
if(r<230){
int u=10;
}
VariantClear(&parm);

VariantCopy(&RangeIsEmpty, &rVal);
VariantCopy(&RangeIsBlank, &rVal1);

//int ww=RangeIsEmpty.dblVal;
//if (RangeIsEmpty.dblVal>0){
//if (RangeIsEmpty.dblVal< actual_column ){
if (RangeIsEmpty.dblVal< acol ){
VariantClear(&rVal);
newrcorner="$A$1:$";
newrcorner+=thecol;
newrcorner+="$"+biaUtils::extractInt(r);
#ifdef _DEBUG
biaLogger::global().debug("LastCell: " + newrcorner);
#endif
int actual_row=r;
//foundcorner=1;
break;

}

VariantClear(&rVal);
VariantClear(&rVal1);
//}
//if(foundcorner){
//foundcorner=0;
//break;
//}

}
 

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