CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 1 of 1
  1. #1
    Join Date
    Mar 2007
    Location
    Argentina
    Posts
    579

    Excel UDF in Dll

    I have read lots of pages on how to make a dll function available for Excel 2003, as a User defined function. For example:

    http://www.codeproject.com/KB/COM/ex...select=2576491

    With they I have achieved making some dll functions without parameters available for excel as User Defined Functions,

    but they don't work with parameters. Worst, when I changed the name of the class, or the main namespace, they stopped working, even after I restored the original names.

    I do not get it. Have no idea what is wrong.

    I attach a very basic VB.NET 2008 project. It contains two functions:

    Code:
            Public Function TestWithoutParameters() As String
                Return "It looks like it works!"
            End Function
            Public Function TestExcel(ByRef PerÃ*odo As Integer, _
                                      ByRef Precipitación() As Double) As Double()
                Return Precipitación
            End Function
    They don't work. I think is a problem with COM, but no idea.

    ¿Can someone give me a hint?

    Microsoft gives little help.

    I attach the project.
    This is the main code:
    Code:
    Imports System.Math
    Imports System
    Imports System.Runtime.InteropServices
    Imports Microsoft.Win32
    
    Namespace MyNamespace
    
        <Guid("d2f1d268-a846-4094-9e7f-c9f0be0ab44d")> _
        <ClassInterface(ClassInterfaceType.AutoDual), _
        ComVisible(True)> _
        Public Class FuncionesSPI
            Public Sub New()
            End Sub
    
            Public Function TestWithoutParameters() As String
                Return "It looks like it works!"
            End Function
            Public Function TestExcel(ByRef PerÃ*odo As Integer, _
                                      ByRef Precipitación() As Double) As Double()
                Return Precipitación
            End Function
    
            'Para interoperabilidad con excel:
            <ComRegisterFunctionAttribute()> _
            Public Shared Sub RegisterFunction(ByVal t As Type)
                Microsoft.Win32.Registry.ClassesRoot.CreateSubKey("CLSID\{" + t.GUID.ToString().ToUpper() + "}\Programmable")
            End Sub
    
            <ComUnregisterFunctionAttribute()> _
            Public Shared Sub UnregisterFunction(ByVal t As Type)
                Microsoft.Win32.Registry.ClassesRoot.DeleteSubKey("CLSID\{" + t.GUID.ToString().ToUpper() + "}\Programmable")
            End Sub
            Private Shared Function GetSubkeyName(ByVal type As Type) As String
                Dim S As New System.Text.StringBuilder()
                S.Append("CLSID\{")
                S.Append(type.GUID.ToString().ToUpper())
                S.Append("}\Programmable")
                Return S.ToString()
            End Function
    
        End Class
    End Namespace
    Attached Files Attached Files
    Last edited by Marraco; July 30th, 2008 at 12:44 PM.
    [Vb.NET 2008 (ex Express)]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured