Excel Add-IN Help

errodr

New member
Joined
Sep 12, 2006
Messages
2
Programming Experience
Beginner
Can someone please point me in the right direction? I am trying to create an Excel add-in using VB.Net 2005/.NET framework 2/Office 2003.

Thanks...
 
Here's a really simple example. Acknowledgements go to Govert van Drimmelen (Code Project)


Create a new ClassLibrary project, call it NAddIn

Goto the project properties an select 'configuration properties' -> 'Build' ->
'Register for COM Interop' to true

Create an empty class and paste the following....


VB.NET:
Imports System
Imports System.Runtime.InteropServices
Namespace NAddIn
 <ClassInterface(ClassInterfaceType.AutoDual)> _
 Public Class Functions
  Public Sub New()
  End Sub
  Public Function Add2(ByVal v1 As Double, ByVal v2 As Double) As Double
   Return v1 + v2
  End Function
  <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
 End Class
End Namespace

  1. Build the NAddIn project to create bin\debug\NAddIn.dll.
  2. Open a new workbook in Excel.
  3. Select Tools, Add-Ins, Automation.
  4. NAddIn.Functions should be listed - select it. OK.
  5. In a cell, type '=Add2(3,4)'
  6. The cell should display 7.
Conratualtions, you've just created your first excel addin.
 
Back
Top