Hi,
I’m trying to learn VSTO I’ve installed Visual Studio Community 2017 and Office 2010 and I’am following Carter Lipper book
I make the following step:
1) launch Visual Studio as administrator and create a new C# class library project.Name the project AutomationAddin. Replace Class1 with the following code:
using System;
using System.Runtime.InteropServices;
using Microsoft.Win32;
namespace AutomationAddIn
{
[Guid("0EDD997D-9C02-4684-B73A-1370D3DD2555")]
[ClassInterface(ClassInterfaceType.AutoDual)]
[ComVisible(true)]
publicclassMyFunctions
{
public MyFunctions()
{
}
publicdouble MultiplyNTimes(double
number1,
double number2,double timesToMultiply)
{
double result = number1;
for (double
i = 0; i < timesToMultiply; i++)
{
result = result * number2;
}
return result;
}
[ComRegisterFunctionAttribute]
publicstaticvoid RegisterFunction(Type type)
{
Registry.ClassesRoot.CreateSubKey(GetSubKeyName(type, "Programmable"));
RegistryKey key = Registry.ClassesRoot.OpenSubKey(GetSubKeyName(type, "InprocServer32"),true);
key.SetValue("",System.Environment.SystemDirectory +@"\mscoree.dll",RegistryValueKind.String);
}
[ComUnregisterFunctionAttribute]
publicstaticvoid UnregisterFunction(Type type)
{
Registry.ClassesRoot.DeleteSubKey(GetSubKeyName(type, "Programmable"),false);
}
privatestaticstring GetSubKeyName(Type type,string
subKeyName)
{
System.Text.StringBuilder s = new System.Text.StringBuilder();
s.Append(@"CLSID\{");
s.Append(type.GUID.ToString().ToUpper());
s.Append(@"}\");
s.Append(subKeyName);
return s.ToString();
}
}
}
2) I’ve got my own GUID string by choosing Tools > Generate GUID.
3) In properties designer for the project ( Build tab) I’ve checked the check box labeled Register for COM Interop,
4) I’ve clickéd Build ( Buld executed with success)
Then I go to my Addin in Excel:
1). Launch Excel, and click the Microsoft Office button in the top-left corner of the window.
2). Choose Excel Options.
3). Click the Add-Ins tab in the Excel Options dialog box.
4). Choose Excel Add-Ins from the combo box labeled Manage, and click the Go button.
5). Click the Automation button in the Add-Ins dialog box.
6). Look through the list of Automation Servers, ……and I don’t find in the the list AutomationAddin.MyFunctions Class… why?,
I’ve tried with many different code found on the .Net and nothing change
Someone can help me to understand?
(Sorry for my English)Thank you