Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
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.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Adding Validation (drop down)

If by function you mean you are trying to put the function in a cell, then
the problem probably is that Excel does not allow a function in a cell to do
anything but return a value to the cell - it can not change environmental
settings and so forth.

--
Regards,
Tom Ogilvy

"William Hearn" wrote in message
om...
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.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Adding Validation (drop down)

Many thanks for your reply

My registered function in xl returns a string but inbetween it has access to the active sheet/active cell and attempts to create a dropdown combo containing a set of values, using the Validation object much in the same way the following vba code would do

Function GetSomeData() as strin

dim str as strin
' do some work to populate the strin

ActiveCell.Selec
ActiveCell.Clea
With Selection.Validatio
.Delet
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:=str
.IgnoreBlank = Tru
.InCellDropdown = Tru
.InputTitle = "
.ErrorTitle = "
.InputMessage = "
.ErrorMessage = "
.ShowInput = Fals
.ShowError = Tru
End Wit
GetSomeData = GetFirstString(str) '
End Function
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Adding Validation (drop down)

and you could not do

=Getsomedata()

in a cell with that function - it would just return #Value

I don't know if that is what you are trying to do, but if it is, it won't
work. At least it won't work with this VBA function. If an xll can get
around that limitation, I can't say, but if you are having problems and
attempting that, then I would think it can't.

--
Regards,
Tom Ogilvy

"Will" wrote in message
...
Many thanks for your reply

My registered function in xl returns a string but inbetween it has access

to the active sheet/active cell and attempts to create a dropdown combo
containing a set of values, using the Validation object much in the same
way the following vba code would do.

Function GetSomeData() as string

dim str as string
' do some work to populate the string

ActiveCell.Select
ActiveCell.Clear
With Selection.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop,

Operator:=xlBetween, Formula1:=str
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = False
.ShowError = True
End With
GetSomeData = GetFirstString(str) '
End Function



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Drop Down Lists: Allow option of adding own data if not in drop do ruperthouse Excel Worksheet Functions 8 July 21st 09 07:29 PM
permenent appearance of the drop down arrow when adding validation toa cell thread Excel Worksheet Functions 2 March 24th 08 05:20 PM
Adding data validation shezzer_1972 Excel Discussion (Misc queries) 3 March 4th 07 07:49 PM
Validation Drop Down Box Duncan, UK Excel Discussion (Misc queries) 2 March 24th 06 11:56 AM
Dynamically adding an in-cell drop-down list (i.e. Validation Object) to a cell? debartsa Excel Programming 5 March 5th 04 08:45 AM


All times are GMT +1. The time now is 05:56 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"