Click here to Skip to main content
16,016,140 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Display a message in a box and close it from the program Pin
Hamid_RT24-Oct-06 20:03
Hamid_RT24-Oct-06 20:03 
Questionffilesystem navigation in c++ 2 Pin
Desmo1624-Oct-06 4:59
Desmo1624-Oct-06 4:59 
AnswerRe: ffilesystem navigation in c++ 2 Pin
Mark Salsbery24-Oct-06 5:19
Mark Salsbery24-Oct-06 5:19 
AnswerRe: ffilesystem navigation in c++ 2 Pin
led mike24-Oct-06 5:22
led mike24-Oct-06 5:22 
GeneralRe: ffilesystem navigation in c++ 2 Pin
Mark Salsbery24-Oct-06 5:27
Mark Salsbery24-Oct-06 5:27 
GeneralRe: ffilesystem navigation in c++ 2 Pin
led mike24-Oct-06 5:32
led mike24-Oct-06 5:32 
GeneralRe: ffilesystem navigation in c++ 2 Pin
David Crow24-Oct-06 6:20
David Crow24-Oct-06 6:20 
Question"FindNext method of Range class failed" - How to make it work. [modified] Pin
Crash224-Oct-06 4:47
Crash224-Oct-06 4:47 
Hello,

Purpose: Search through a single column in a single worksheet to find duplicate cell items.

Description: I can use 'Find' without any problems for the inital search however when I try to use it again I get an COleException with either no error description or 'type mismatch' if I pass in an 'After' cell address. When I use the 'FindNext' method I get the error "FindNext method of Range class failed". I need help!

I'm using Office 2003, VC++ 2003, Automation import via VS.



CODE for 'FindNext':

FindNext( CString afterAddress, CRange *pFoundRange )
{
bool result = false;

CWorksheets excelWorksheets( m_CurrentWorkbook.get_Worksheets() );
CWorksheet Worksheet( excelWorksheets.get_Item( COleVariant( (short)m_CurrentWorksheetIndex ) ) );

Worksheet.Activate();

CRange excelRange( Worksheet.get_UsedRange() );

VARIANT afterCellAddress;

VariantInit( &afterCellAddress );

afterCellAddress.vt = VT_BSTR;
afterCellAddress.bstrVal = afterAddress.AllocSysString();

excelRange.Activate();

pFoundRange->AttachDispatch ( excelRange.FindNext( afterCellAddress ) );//'FindNext method of Range class failed' here

VariantClear( &afterCellAddress );

result = true;

return result;

}

CODE for 'Find' being used twice:


Find( CString dataToFind, CRange *pFoundRange, CString AfterAddress ){


CWorksheets excelWorksheets( m_CurrentWorkbook.get_Worksheets() );
CWorksheet Worksheet( excelWorksheets.get_Item( COleVariant( ( short )m_CurrentWorksheetIndex ) ) );

Worksheet.Activate();
CRange excelRange( Worksheet.get_UsedRange() );

VARIANT valueToFind;
VARIANT afterCellAddress;

VariantInit( &afterCellAddress );
VariantInit( &valueToFind );

afterCellAddress.vt = VT_BSTR;
valueToFind.vt = VT_BSTR;

afterCellAddress.bstrVal = AfterAddress.AllocSysString();
valueToFind.bstrVal = dataToFind.AllocSysString();

LPDISPATCH foundRange = NULL;

TRY{
if( AfterAddress.GetLength() > 0 ){
foundRange = excelRange.Find( valueToFind ,
afterCellAddress,
xlValues,
xlWhole,
vOptional,
xlNext,
vTrue,
vOptional,
vOptional );
}
else {
foundRange = excelRange.Find( valueToFind ,
vOptional,
xlValues,
xlWhole,
vOptional,
xlNext,
vTrue,
vOptional,
vOptional );
}

if( foundRange != NULL ){
pFoundRange->AttachDispatch ( foundRange );
}

VariantClear( &afterCellAddress );
VariantClear( &valueToFind );

result = true;
}
CATCH( CException, E ){
result = false;

}END_CATCH
}




-- modified at 10:53 Tuesday 24th October, 2006
AnswerRe: "FindNext method of Range class failed" - How to make it work. [modified] Pin
Member 80221232-Aug-13 23:34
Member 80221232-Aug-13 23:34 
Questionproblem with nested types and constructor parameters Pin
yaniv1724-Oct-06 4:47
yaniv1724-Oct-06 4:47 
Questionfilesystem navigation in c++ Pin
Desmo1624-Oct-06 4:44
Desmo1624-Oct-06 4:44 
AnswerRe: filesystem navigation in c++ Pin
Mark Salsbery24-Oct-06 4:52
Mark Salsbery24-Oct-06 4:52 
GeneralRe: filesystem navigation in c++ Pin
Desmo1624-Oct-06 5:07
Desmo1624-Oct-06 5:07 
GeneralRe: filesystem navigation in c++ Pin
Mark Salsbery24-Oct-06 5:14
Mark Salsbery24-Oct-06 5:14 
GeneralRe: filesystem navigation in c++ Pin
Desmo1624-Oct-06 5:16
Desmo1624-Oct-06 5:16 
GeneralRe: filesystem navigation in c++ Pin
Mark Salsbery24-Oct-06 5:22
Mark Salsbery24-Oct-06 5:22 
AnswerRe: filesystem navigation in c++ Pin
Hamid_RT24-Oct-06 20:02
Hamid_RT24-Oct-06 20:02 
QuestionHow to Debug Pin
sivaprasadroy24-Oct-06 3:47
sivaprasadroy24-Oct-06 3:47 
AnswerRe: How to Debug Pin
shadrach_india24-Oct-06 4:12
shadrach_india24-Oct-06 4:12 
AnswerRe: How to Debug Pin
Hamid_RT24-Oct-06 20:05
Hamid_RT24-Oct-06 20:05 
QuestionWebcam preview Pin
ceejeeb24-Oct-06 3:32
ceejeeb24-Oct-06 3:32 
AnswerRe: Webcam preview Pin
Mark Salsbery24-Oct-06 4:29
Mark Salsbery24-Oct-06 4:29 
QuestionRe: Webcam preview [modified] Pin
ceejeeb24-Oct-06 4:31
ceejeeb24-Oct-06 4:31 
AnswerRe: Webcam preview Pin
Mark Salsbery24-Oct-06 5:32
Mark Salsbery24-Oct-06 5:32 
QuestionEventLog Pin
shadrach_india24-Oct-06 3:24
shadrach_india24-Oct-06 3:24 

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.