CVErr, Excel and VB .NET

H

Howard Kaikow

Many Excel macros/add-ins rely on the use of the VB/VBA CVErr function.

Alas, VB .NET does not support the CVErr function.

Does Excel 2003, Office 2003 or Visual Studio Tools for Office provide a
substitute?
 
K

Keith Willshaw

Howard Kaikow said:
Many Excel macros/add-ins rely on the use of the VB/VBA CVErr function.

Alas, VB .NET does not support the CVErr function.

Does Excel 2003, Office 2003 or Visual Studio Tools for Office provide a
substitute?

But in .net you can achieve the same functionallity
by using the exception handling routines it does support

In VB6 you'd call a VB error code as follows

Function CalculateDouble(Number)
If IsNumeric(Number) Then
CalculateDouble = Number * 2 ' Return result.
Else
CalculateDouble = CVErr(2001) ' Return a user-defined error
End If ' number.
End Function


In .net you'd throw an exception to do the same thing
with the call

Throw new InvalidOperationException("Invalid Input to Function")

Keith
 
H

Howard Kaikow

Yes, I recall, perhaps incorrectly, that special error codes in Excel, such
as xlErrValue, required use of a Variant.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top