C
Charles
Hello
I am trying to create a Hello World com add-in that I can call from
VBA in Office 2003. I found various step by step guides on google, but
none really works.
I am using Visual Studio Express 2008.
I created a new Class Library project, went into Assembly information,
and made it "COM Visible". I then went into Signing and clicked Sin
the assembly, created as "password.pfx" file with a 6+ letters
password.
I have only one class, which looks like this:
Option Compare Text
Option Strict Off
Imports System
Imports System.Runtime.InteropServices
Imports Microsoft.Win32
<ClassInterface(ClassInterfaceType.AutoDual), ComVisible(True)> _
Public Class TestClass
Public Sub HelloWorld()
MsgBox("Hello World!")
End Sub
<ComRegisterFunctionAttribute()> _
Public Shared Sub RegisterFunction(ByVal type As Type)
Registry.ClassesRoot.CreateSubKey(GetSubkeyName(type))
End Sub
<ComUnregisterFunctionAttribute()> _
Public Shared Sub UnregisterFunction(ByVal type As Type)
Registry.ClassesRoot.DeleteSubKey(GetSubkeyName(type), False)
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
I then compile. I go into Excel, VB Editor, create a module, go into
Tools/References, click on Browse and pick the DLL in the Release
folder. At this point it says it cannot add the reference to the
specified file.
Would someone be kind enough to indicate where I missed a step?
Alternatively if you know a good step by step guide (or sample project
code) that I could use, it would be much appreciated!
thanks in advance!
Charles
I am trying to create a Hello World com add-in that I can call from
VBA in Office 2003. I found various step by step guides on google, but
none really works.
I am using Visual Studio Express 2008.
I created a new Class Library project, went into Assembly information,
and made it "COM Visible". I then went into Signing and clicked Sin
the assembly, created as "password.pfx" file with a 6+ letters
password.
I have only one class, which looks like this:
Option Compare Text
Option Strict Off
Imports System
Imports System.Runtime.InteropServices
Imports Microsoft.Win32
<ClassInterface(ClassInterfaceType.AutoDual), ComVisible(True)> _
Public Class TestClass
Public Sub HelloWorld()
MsgBox("Hello World!")
End Sub
<ComRegisterFunctionAttribute()> _
Public Shared Sub RegisterFunction(ByVal type As Type)
Registry.ClassesRoot.CreateSubKey(GetSubkeyName(type))
End Sub
<ComUnregisterFunctionAttribute()> _
Public Shared Sub UnregisterFunction(ByVal type As Type)
Registry.ClassesRoot.DeleteSubKey(GetSubkeyName(type), False)
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
I then compile. I go into Excel, VB Editor, create a module, go into
Tools/References, click on Browse and pick the DLL in the Release
folder. At this point it says it cannot add the reference to the
specified file.
Would someone be kind enough to indicate where I missed a step?
Alternatively if you know a good step by step guide (or sample project
code) that I could use, it would be much appreciated!
thanks in advance!
Charles