Custom ENUM with UDF

177 views
Skip to first unread message

Alberto Ghiglia

unread,
Sep 7, 2017, 8:14:48 AM9/7/17
to exce...@googlegroups.com

Hello Govert

I was trying to use a custom public enum in a UDF but Visual Studio seems not to accept them.

Given Message is “Initialization [Error] Method not registered…” and the UDF is not enlisted in the formula

 

I was also trying to insert the enum (in addition to the creation of a public enum in a class) as Names in the Workbook

(In the WorkBookActivate Event I wrote:

                CurrentExcelApplication.ActiveWorkbook.Names.Add(Name:="Sfondo", RefersToR1C1:="=0")

                CurrentExcelApplication.ActiveWorkbook.Names.Add(Name:="Testo", RefersToR1C1:="=1")

..but there is still the same error

 

Is it there a way to bypass this?

 

Thanks

Alberto

 

Govert van Drimmelen

unread,
Sep 8, 2017, 11:27:40 AM9/8/17
to exce...@googlegroups.com

Hi Alberto,

 

The basic Excel-DNA library doesn’t have any special enum support, but the Registration extension (https://github.com/Excel-DNA/Registration ) allows you to add this. The parameter conversion there just does automatic enum <-> string conversion for enum parameters – the name-based approach might be nicer.

 

-Govert

--
You received this message because you are subscribed to the Google Groups "Excel-DNA" group.
To unsubscribe from this group and stop receiving emails from it, send an email to exceldna+u...@googlegroups.com.
To post to this group, send email to exce...@googlegroups.com.
Visit this group at https://groups.google.com/group/exceldna.
For more options, visit https://groups.google.com/d/optout.

Alberto Ghiglia

unread,
Sep 25, 2017, 7:51:08 AM9/25/17
to exce...@googlegroups.com

Hi Govert,

I included exceldna.registration  as follows

1)      In the .dna file:

<ExternalLibrary Path="AlanTools.dll" ExplicitRegistration="true" LoadFromBytes="true" Pack="true" ComServer="true"  />

2)      In the .AutoOpen Sub:

      Dim functions = ExcelRegistration.GetExcelFunctions().ToList()

         Dim Commands = ExcelRegistration.GetExcelCommands().ToList()

        ExcelRegistration.RegisterFunctions(functions)

 

The Function is as follows

   <ExcelFunction(IsVolatile:=True, IsMacroType:=True, Description:="Ritorna il colore dello Sfondo", Name:="XCOLORE")> _

        Public Shared Function XColore(<ExcelArgument(AllowReference:=True, Description:="Cella di riferimento")> Indirizzo As Object, _

                                      C As Enumerables.Colore) As Long

 

But I get nearly the same error: “Registration [Error] Method not registered due to unsupported signature: 'Func`3.Invoke' : DnaMarshalException - Unknown Data Type: AlanTools.Enumerables+Colore

 

How can I registrate the ENUM?

I tried to include in the .GetExcelFunctions() but I don’t know how to do

 

Many Thanks

 

Alberto

 

 

 

 

Da: exce...@googlegroups.com [mailto:exce...@googlegroups.com] Per conto di Govert van Drimmelen
Inviato: venerdì 8 settembre 2017 17:28
A: exce...@googlegroups.com
Oggetto: RE: [ExcelDna] Custom ENUM with UDF

Alberto Ghiglia

unread,
Sep 27, 2017, 10:17:09 AM9/27/17
to Excel-DNA
Hi,
do someone have some hints, please?

Thanks in advance

Alberto
Reply all
Reply to author
Forward
0 new messages