STEP 1: creating Excel 2010 add-in
I created a new project, Excel 2010 add-in, .Net 4 framework
I added a class file to it "Name.cs", interface "iName.cs" and added a function to it
[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
public interface iName
{
string getName();
}
[ClassInterface(ClassInterfaceType.None)]
public class Name
{
public string getName()
{
return "Hello";
}
}
STEP 2: Configuring build events
I configured the build events of the pro
"%Windir%\Microsoft.NET\Framework\v4.0.30319\regasm" /codebase /tlb
"$(MSBuildProjectDirectory)\$(OutputPath)$(AssemblyName).dll"
This will register the Dll so that it will be available in the references
column in the Excel
STEP 3: Adding reference in Excel macro
I created a module, in the tools-> reference I added the NameProvider
(name of that assembly/project) add-in that is available after I built the Excel add-in project
I tried to create an object for that added reference
Public Sub test()
Dim nameObj as NameProvider.Name
Dim name as string
Set nameObj = new NameProvider.Name 'error 429 occurs here
name = nameObj.getName() 'getName function automatically comes after .
End Sub
For Office 64bit you need to compile your assembly as x64 compatible, and register it with the 64bit framework by using the regasm from the Framework 64 folder.
"%Windir%\Microsoft.NET\Framework64\v4.0.30319\regasm" /codebase /tlb
"$(MSBuildProjectDirectory)\$(OutputPath)$(AssemblyName).dll"
%Windir%\\Microsoft.NET\\Framework\\v4.0.30319\\regasm -> %Windir%\\Microsoft.NET\\Framework 64 \\v4.0.30319\\regasm
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.