View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
William Hearn William Hearn is offline
external usenet poster
 
Posts: 1
Default Adding Validation (drop down)

Hello

I have created an XLL to register a set of functions within xl. The
return values of certain ones I wish to populate a drop down from. I
can successfully do this by attaching a toolbar and a button and
running the following on the on click event. (via the xl object model)

if (m_XLApplication)
{
Excel::RangePtr pRange = m_XLApplication-ActiveCell;
CComVariant vEmpty(DISP_E_PARAMNOTFOUND, VT_ERROR);
CString strRange = (LPCSTR)_bstr_t
(pRange-GetAddress(VARIANT_TRUE, VARIANT_TRUE, Excel::xlR1C1,
VARIANT_FALSE, vEmpty));

Excel::ValidationPtr pValidation = pRange-Validation;
CString str = _T("Test1, Test2, Test3");
try
{
pValidation-Delete();
pValidation-Add(Excel::xlValidateList,
(CComVariant)xlValidAlertStop, (CComVariant)Excel::xlBetween,
(_variant_t)str);
pValidation-IgnoreBlank = VARIANT_TRUE;
pValidation-InCellDropdown = VARIANT_TRUE;
pValidation-InputTitle = OLESTR("");
pValidation-ErrorMessage = OLESTR("");
pValidation-ShowInput = VARIANT_FALSE;
pValidation-ShowError = VARIANT_TRUE;
}
catch (_com_error e)
{
OutputDebugString(e.Description());
}

This sucessfully creates the drop down entry.

When I attempt to drive this from a function that I have registered
i.e exactly the same code but called from inside an exported XLL
function. An exception is thrown with no error code or description, as
I attempt the 'add' for validation. The m_XLAppplication is the
active xl instance CComPtr<Excel::_Application and I have tested
items such as the range address to make sure the application is valid
before attempting to add the Validation to the selected range.