Hi Albrecht,
I follow the same steps, and everything works fine for me. I have Windows 10 and VS Pro, but don't think that makes a difference. What I think happened is that a small install script in the ExcelDna.AddIn NuGet package was supposed to run but maybe did not. That left you with a file called something like ExcelDna-Template.dna which should have been renamed and had some template entries that should be filled in. It is causing the errors you see. I don't know why the install script did not run for you.
Better would be to make a new project using the "Class Library" option rather than "Class Library (.NET Framework)". Choose any .NET version in the wizard - we'll change to .NET Framework 4.7.2 in the project file afterwards. Once you have the project, replace everything in the .csproj file so that it looks like this:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net472</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="ExcelDna.AddIn" Version="1.8.0" />
</ItemGroup>
</Project>
With a new project and this project file, you can then add a function, compile and run. Everything should work fine.
I will try to explain more detail.
With .NET there are old-style project files, and SDK-style project files. When you make a library with “Class Library (.NET Framework)” you get an old-style project file. When you make a library with “Class Library” you get an SDK-style project file. By default the SDK-style project file wizard is set up to target .NET Core (some version of .NET 5+), but you can also target .NET Framework (e.g., .NET Framework 4.7.2) from an SDK-style project. SDK-style project files are better, and you should use them whether you target .NET Framework 4.x or .NET 5+ (aka .NET Core). Existing projects that use old-style project files should be converted to SDK-style project files, but that can be a bit tricky.
(To be clear, targeting .NET Framework 4.x with your Excel-DNA add-in is a good idea - there are many benefits to using the stable .NET Framework rather than the new .NET core runtimes which change often. This discussion is just about which type of project file to use for building your projects. Newer SDK-style files can target both runtime generations.)
When using old-style project files, there are two styles of managing the NuGet packages: a packages.config file or with <PackageReference> entries in the proejct file. With SDK-style project files you would only use <PackageReference> entries - you can add the packages with the VS interface or by editing the .csproj file directly.Hi Albrecht,
Please start a new discussion for new questions – that helps future me and others find the relevant topic more easily.
It’s not easy to call the ribbon procedure from VBA.
But you can define and register macro commands in your add-in like this
[ExcelCommand(ShortCut ="{F5}")] // Or something like "^w" to mean Ctrl + w
public static void DoTheWork()
{
var app = ExcelDnaUtil.Application as Application;
app.ActiveSheet.Range["A1"].Value = "Hello from a command!";
}
Such a macro can be:
You can directly add a shortcut to the ExcelCommand definition, as above, but sometimes you cannot override the built-in shortcuts this way, so "^c" (Ctrl + C) won’t work.
-Govert
--
You received this message because you are subscribed to the Google Groups "Excel-DNA" group.
To unsubscribe from this group and stop receiving emails from it, send an email to exceldna+u...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/exceldna/d25c05fc-7512-423a-9466-d1efd53e1e9en%40googlegroups.com.