Custom User Defined Functions in AxSpreadsheet

H

Howard

I have 3 user defined functions to be used in my VB.Net application using the
AxSpreadsheet control. How do I get the control to recognize these as
functions, showing the formula when in edit mode and the value when not?
 
S

Sahil Ebrahim

Firstly you need to create a class library using visual studio and then
define functions within that file.

Imports System
Imports System.Runtime.InteropServices
Imports Microsoft.Win32


<ClassInterface(ClassInterfaceType.AutoDual), ComVisible(True)> _
Public Class AddinFunctions

<ComRegisterFunctionAttribute()> _
Shared Sub RegisterFunction(ByVal type As Type)
Registry.ClassesRoot.CreateSubKey("CLSID\{" _
& type.GUID.ToString().ToUpper() & "}\Programmable")
End Sub

<ComUnregisterFunctionAttribute()> _
Shared Sub UnregisterFunction(ByVal type As Type)
Registry.ClassesRoot.DeleteSubKey("CLSID\{" _
& type.GUID.ToString().ToUpper() & "}\Programmable", False)
End Sub

Function Travel_Expenses(ByVal Exc)
Travel_Expenses = "This is travel exp"
End Function

End Class


^^That was an example
Once you have created the .dll add it to your project reference.

Thereafter apply this code for your Axspreadsheet object.

atp = CreateObject("OWCAddin.AddinFunctions")
AxSpreadsheet1.AddIn(addIn:=atp)

To make sure you have done the referencing properly, check your object
browser and all your functions should appear there.

Regards
 

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