In VBA, there is a function named VBA.Conversion.CVErr that accepts a
numeric value indicating an error and converts it to a real Variant
Error object. The values you feed to CVErr are enumerated within the
Excel.XlCVError enum and have the values:
Excel.XlCVError.xlErrDiv0 = 2007 => #DIV/0!
Excel.XlCVError.xlErrNA = 2042 => #N/A
Excel.XlCVError.xlErrName = 2029 => #NAME?
Excel.XlCVError.xlErrNull = 2000 => #NULL
Excel.XlCVError.xlErrNum = 2036 => #NUM!
Excel.XlCVError.xlErrRef = 2023 => #REF
Excel.XlCVError.xlErrValue = 2015 => #VALUE!
The typelib for Excel is within the Excel exe file, so you can get the
enumerated values from the exe. The CVErr function resides in the VBA
DLL, typically
C:\Program Files\Common Files\Microsoft Shared\VBA\VBA6\VBE6.DLL
If you need to find the DLL in another location, take a trip through
the registry using the GUID {000204EF-0000-0000-C000-000000000046}.
Specify the return type of the function as an Object and then write
code in the caller to determine whether the returned value is an error
object or something else.
In VSTO, you get an reference to the host application at startup.
Store that reference is some global variable and then use that
reference to call the desired calculation. E.g,
// Declare
Excel.Application XLApp;
// Set
XLApp = HostApplication;
// Calculate
XLApp->Calculate; // or
XLApp->CalculateFull; // or
XLApp->CalculateFullRebuild;
Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)
Hello developers,
I have a class like this one below, registered as COM server and added to
Add Ins.
[Guid("some guid here")]
[ClassInterface(ClassInterfaceType.AutoDual)]
[ComVisible(true)]
public class Functions {
public object MyFunction() {
return ...
}
}
How do I return special values like #NAME!, #VALUE!, etc from my function?
Another question: how do I force Excel workbook to recalculate (F9) from
my
VSTO Add In?
Thank you for any hints.
Tomasz