M
Mark Wilson
I have a Word COM Addin that needs to find and delete a string of text that
is in the body of an Outlook 2003 e-mail message. The ASCII string is
converted to a BSTR an passed as a parameter to a routine called
FindTextString. The string exists in the document because it was previously
inserted with a call to InsertAfter. As long as the length of the search
string is 256 characters or less, the Find works properly. If the search
string is 257 characters or larger, the call to Find fails with error code
0x80020009 (Exception occurred).
Is there a size restriction on Find?
----------------------------
BOOL CClassWord::FindTextString(BSTR bsTextString)
{
HRESULT hr;
bool bResult;
VARIANT vtDocument; VariantInit(&vtDocument);
VARIANT vtRange; VariantInit(&vtRange);
VARIANT vtFind; VariantInit(&vtFind);
VARIANT vtParam; VariantInit(&vtParam);
VARIANT vtParam1[15]; VariantInit(vtParam1);
hr = GetProperty(m_pParentApp,L"ActiveDocument",&vtDocument);
hr = GetProperty(vtDocument.pdispVal, L"content", &vtRange);
hr = GetProperty(vtRange.pdispVal, L"Find", &vtFind);
vtParam1[14].vt = VT_BSTR; vtParam1[14].bstrVal =
::SysAllocString(bsTextString);
vtParam1[13].vt = VT_ERROR; vtParam1[13].scode = DISP_E_PARAMNOTFOUND;
vtParam1[12].vt = VT_ERROR; vtParam1[12].scode = DISP_E_PARAMNOTFOUND;
vtParam1[11].vt = VT_ERROR; vtParam1[11].scode = DISP_E_PARAMNOTFOUND;
vtParam1[10].vt = VT_ERROR; vtParam1[10].scode = DISP_E_PARAMNOTFOUND;
vtParam1[9].vt = VT_ERROR; vtParam1[9].scode = DISP_E_PARAMNOTFOUND;
vtParam1[8].vt = VT_ERROR; vtParam1[8].scode = DISP_E_PARAMNOTFOUND;
vtParam1[7].vt = VT_ERROR; vtParam1[7].scode = DISP_E_PARAMNOTFOUND;
vtParam1[6].vt = VT_ERROR; vtParam1[6].scode = DISP_E_PARAMNOTFOUND;
vtParam1[5].vt = VT_ERROR; vtParam1[5].scode = DISP_E_PARAMNOTFOUND;
vtParam1[4].vt = VT_ERROR; vtParam1[4].scode = DISP_E_PARAMNOTFOUND;
vtParam1[3].vt = VT_ERROR; vtParam1[3].scode = DISP_E_PARAMNOTFOUND;
vtParam1[2].vt = VT_ERROR; vtParam1[2].scode = DISP_E_PARAMNOTFOUND;
vtParam1[1].vt = VT_ERROR; vtParam1[1].scode = DISP_E_PARAMNOTFOUND;
vtParam1[0].vt = VT_ERROR; vtParam1[0].scode = DISP_E_PARAMNOTFOUND;
hr = CallMethod(vtFind.pdispVal, L"Execute", &vtParam, 15, vtParam1);
::SysFreeString(vtParam1[14].bstrVal);
if (hr == 0x80020009)
MessageBox(NULL, "Exception occurred.", "FindTextString", MB_OK);
if (vtParam.boolVal == VARIANT_TRUE) bResult = true;
else bResult = false;
VariantClear(vtParam1);
VariantClear(&vtParam);
VariantClear(&vtFind);
VariantClear(&vtRange);
VariantClear(&vtDocument);
return bResult;
}
is in the body of an Outlook 2003 e-mail message. The ASCII string is
converted to a BSTR an passed as a parameter to a routine called
FindTextString. The string exists in the document because it was previously
inserted with a call to InsertAfter. As long as the length of the search
string is 256 characters or less, the Find works properly. If the search
string is 257 characters or larger, the call to Find fails with error code
0x80020009 (Exception occurred).
Is there a size restriction on Find?
----------------------------
BOOL CClassWord::FindTextString(BSTR bsTextString)
{
HRESULT hr;
bool bResult;
VARIANT vtDocument; VariantInit(&vtDocument);
VARIANT vtRange; VariantInit(&vtRange);
VARIANT vtFind; VariantInit(&vtFind);
VARIANT vtParam; VariantInit(&vtParam);
VARIANT vtParam1[15]; VariantInit(vtParam1);
hr = GetProperty(m_pParentApp,L"ActiveDocument",&vtDocument);
hr = GetProperty(vtDocument.pdispVal, L"content", &vtRange);
hr = GetProperty(vtRange.pdispVal, L"Find", &vtFind);
vtParam1[14].vt = VT_BSTR; vtParam1[14].bstrVal =
::SysAllocString(bsTextString);
vtParam1[13].vt = VT_ERROR; vtParam1[13].scode = DISP_E_PARAMNOTFOUND;
vtParam1[12].vt = VT_ERROR; vtParam1[12].scode = DISP_E_PARAMNOTFOUND;
vtParam1[11].vt = VT_ERROR; vtParam1[11].scode = DISP_E_PARAMNOTFOUND;
vtParam1[10].vt = VT_ERROR; vtParam1[10].scode = DISP_E_PARAMNOTFOUND;
vtParam1[9].vt = VT_ERROR; vtParam1[9].scode = DISP_E_PARAMNOTFOUND;
vtParam1[8].vt = VT_ERROR; vtParam1[8].scode = DISP_E_PARAMNOTFOUND;
vtParam1[7].vt = VT_ERROR; vtParam1[7].scode = DISP_E_PARAMNOTFOUND;
vtParam1[6].vt = VT_ERROR; vtParam1[6].scode = DISP_E_PARAMNOTFOUND;
vtParam1[5].vt = VT_ERROR; vtParam1[5].scode = DISP_E_PARAMNOTFOUND;
vtParam1[4].vt = VT_ERROR; vtParam1[4].scode = DISP_E_PARAMNOTFOUND;
vtParam1[3].vt = VT_ERROR; vtParam1[3].scode = DISP_E_PARAMNOTFOUND;
vtParam1[2].vt = VT_ERROR; vtParam1[2].scode = DISP_E_PARAMNOTFOUND;
vtParam1[1].vt = VT_ERROR; vtParam1[1].scode = DISP_E_PARAMNOTFOUND;
vtParam1[0].vt = VT_ERROR; vtParam1[0].scode = DISP_E_PARAMNOTFOUND;
hr = CallMethod(vtFind.pdispVal, L"Execute", &vtParam, 15, vtParam1);
::SysFreeString(vtParam1[14].bstrVal);
if (hr == 0x80020009)
MessageBox(NULL, "Exception occurred.", "FindTextString", MB_OK);
if (vtParam.boolVal == VARIANT_TRUE) bResult = true;
else bResult = false;
VariantClear(vtParam1);
VariantClear(&vtParam);
VariantClear(&vtFind);
VariantClear(&vtRange);
VariantClear(&vtDocument);
return bResult;
}