Hello Tomasz,
I¡¯m not quite clear about you said ¡°return special values form myfunction
¡±, are you trying to
creating a UDF in managed code or you are trying to expose this class to
the other solutions
such as VBA.
If you are creating a UDF in managed code would you please talk about what
is your objective of
return special values like #NAME!, #VALUE! from MyFunction? Do you mean you
want to handle the
exception in MyFunction or something else?
I think I need more details about your scenario to clarify this question.
Due to my test the error occurs when call a UDF won¡¯t reach the managed
code, the break point in
managed side will never hit after you give a wrong type parameter when I
call MyFunction in
Excel. To work this around, I suggest you call your UDF(MyFunction) through
VBA, thus, we could
return the Error Code by using
VBA.Conversion.CVErr method which receives a parameter of Excel.XlCVError
type. About the
details of Excel.XlCVError you could refer to this link:
http://msdn.microsoft.com/en-
us/library/microsoft.office.interop.excel.xlcverror(office.11 ).aspx
Following sample demonstrate a usage of CVErr method:
Public Function TestErr(TestPara As Variant) As Variant
TestErr = CVErr(xlErrNA)
End Function
To call UDF in managed code from VBA please follow the steps in this link:
http://blogs.msdn.com/pstubbs/archiv...31/344964.aspx
If you are trying to expose Functions class, please follow this walk
through article in MSDN:
http://msdn.microsoft.com/en-us/library/bb608614.aspx
Briefly, Functions class need to inherits a interface you defined, this
interface will be used
to interop with VBA.
To your last question ¡°Another question: how do I force Excel workbook to
recalculate (F9) from
my
VSTO Add In?¡°
In Excel Object Model we could call Application.Calculate() method to force
Excel workbook to
recalculate, for more information about Calculate() method please refer to
this link:
http://msdn.microsoft.com/en-us/library/bb211549.aspx
Best regards,
Tim Li
Microsoft Online Community Support
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how
we can improve the support we provide to you. Please feel free to let my
manager know what you
think of the level of service provided. You can send feedback directly to
my manager .