LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default VB.NET: How to declare a parameter in a worksheet-function

I'm playing with a sample found on
http://www.cpearson.com/Excel/Creati...nctionLib.aspx . My idea is to
create a class library in VB.NET 2008 that I can use as automation add-in in
Excel.

In the following code snippet the function 'DivideBy2' has a parameter of
type Double.
- When passing a number as parameter e.g. "=DivideBy2(50)", I get a correct
result.
- If I pass a cell reference as paramter e.g. "=DivideBy2($A$1)", I get a
"#Value" error ("A value used in the formula is of the wrong type"

Could anybody give me a hint how to solve this problem?

Many thanks for your suggestions,
Etienne

Here's the code:

<ClassInterface(ClassInterfaceType.AutoDual), ComVisible(True)Public Class
SampleFunctions

Public Function DivideBy2(ByVal pDouble As Double) As Double

Return pDouble / 2

End Function

<ComRegisterFunctionAttribute()Public Shared Sub RegisterFunction(ByVal
pType As Type)

Registry.ClassesRoot.CreateSubKey(GetSubkeyName(pT ype))

End Sub

<ComUnregisterFunctionAttribute()Public Shared Sub
UnregisterFunction(ByVal pType As Type)

Registry.ClassesRoot.DeleteSubKey(GetSubkeyName(pT ype), False)

End Sub

Private Shared Function GetSubkeyName(ByVal pType As Type) As String

Dim S As New System.Text.StringBuilder()

S.Append("CLSID\{")

S.Append(pType.GUID.ToString().ToUpper())

S.Append("}\Programmable")

Return S.ToString()

End Function

End Class


 
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
How to declare the active worksheet? Mekinnik Excel Programming 1 November 1st 07 07:43 PM
Private Declare Function David A. Excel Programming 6 July 31st 07 06:38 PM
Lib parameter in Function Declare ojv[_2_] Excel Programming 4 June 12th 07 07:40 AM
Declare and array in a function Dave Excel Programming 3 September 30th 06 03:41 AM
VBA (or other) worksheet function parameter insight Marc Deveaux[_3_] Excel Programming 3 September 30th 04 11:44 PM


All times are GMT +1. The time now is 10:38 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"