In einem anderen Forum wurde mir nun geholfen.
Ich versuche das Erfahrene kurz weiter geben.
Hier mein Code:
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48:
| using System; using System.Runtime.InteropServices; using Microsoft.Win32; using System.IO;
namespace NAddIn { [ClassInterface(ClassInterfaceType.AutoDual)] public class Functions { public Functions() { } public double Adddbl(double v1, double v2) { return v1 + v2; }
[ComRegisterFunctionAttribute] public static void RegisterFunction(System.Type t) { string guidPath = String.Format("CLSID\\{{{0}}}", t.GUID.ToString().ToUpper()); string mscoreePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "mscoree.dll"); string inprocServer32Path = String.Format("{0}\\{1}", guidPath, "InprocServer32"); string programmablePath = String.Format("{0}\\{1}", guidPath, "Programmable");
RegistryKey key = Registry.ClassesRoot.OpenSubKey(inprocServer32Path, true);
key.SetValue("", mscoreePath);
Registry.ClassesRoot.CreateSubKey(programmablePath); } [ComUnregisterFunctionAttribute] public static void UnregisterFunction(System.Type t) { string guidPath = String.Format("CLSID\\{{{0}}}", t.GUID.ToString().ToUpper()); string inprocServer32Path = String.Format("{0}\\{1}", guidPath, "InprocServer32"); string programmablePath = String.Format("{0}\\{1}", guidPath, "Programmable");
RegistryKey key = Registry.ClassesRoot.OpenSubKey(inprocServer32Path, true); key.SetValue(String.Empty, string.Empty);
Registry.ClassesRoot.DeleteSubKey(programmablePath); }
} } |
Folgende Einstellung ist zu machen:
Projekt > Eigenschaften > Anwendung > Assemblyinformationenn... dort auf die CheckBox "Assembly COM-sichtbar machen" klicken.
Dann die Bibliothek erstellen:
Zitat: |
Menü Erstellen, oder Strg+Umsch+B.
|
Dann die Registrierung durchführen:
Zitat: |
RegAsm.exe kannst Du über einen Post-Build-Befehl automatisch ausführen lassen (Projekt > Eigenschaften > Buildereignisse):
"C:\Windows\Microsoft.NET\Framework\v4.0.30319\RegAsm.exe" "$(TargetPath)" /codebase
|
Dann Excel öffnen und die Funktion laden:
Zitat: |
Automations-Add-Ins können über Datei > Optionen > Add-Ins > Verwalten: Excel-Add-Ins> Gehe zu... > Automatisierung... hinzugefügt werden.
Die Funktion heist dort: NAddIn.Functions
|
Grüße