Missing intellisense when using ExcelDnaUtil.Application

41 views
Skip to first unread message

Ólavur Nón

unread,
May 23, 2024, 9:16:31 AMMay 23
to Excel-DNA
Hello Govert,

Amazing project, thank you alot for this!

I need help regarding accessing internal functions (accessible through VBA in "vanilla Excel") using the C# framework. My final result is to be able to copy "Named Constants" from one Excel-file to another by a single button.

The current problem i'm facing is that i don't have Intellisense when using `ExcelDnaUtil.Application` like so:

```
[ExcelCommand(MenuName = "Test", MenuText = "Range Set")]
public static void RangeSet()
{
    dynamic xlApp = ExcelDnaUtil.Application;

    xlApp.Range["F1"].Value = "Testing 1... 2... 3... 4";
}
```

This code from the Excel-dna webpage works, but intellisense does not give me any help in typing the "Range" function. This makes it difficult to know what functions i have to call in order to achieve my goal. Is it possible to get intellisense for xlApp?

If there is a post discussing this, then i have not found it, and you are welcome to refer me to this post.

Kind regards,
Ólavur Nón

Ólavur Nón

unread,
May 23, 2024, 9:35:30 AMMay 23
to Excel-DNA
I'll now let you know that i am a newbie at Visual Studio 2022 and C# (installed Visual Studio last week for the first time), so i am learning much about all this right now.

I figured out, that i did not have "Microsoft.Office.Interop.Excel" added as a dependency in "Dependencies/COM". I managed to add the dependency by following these instructions from Microsoft. Now i have intellisense for xlApp by doing so:
```
namespace My_Plugin
{

    using ExcelDna.Integration;
    using Excel = Microsoft.Office.Interop.Excel;

    public static class MyClass
    {

        [ExcelCommand(MenuName = "Test", MenuText = "Range Set")]
        public static void RangeSet()
        {
            Excel.Application xlApp = (Excel.Application)ExcelDnaUtil.Application;


            xlApp.Range["F1"].Value = "Testing 1... 2... 3... 4";
            xlApp.ThisWorkbook
           
        }
    }
}
```

Terry Aney

unread,
May 24, 2024, 9:47:51 AMMay 24
to Excel-DNA
Unfortunately, a lot of the objects returned from properties in COM Interop (i.e. Worksheet, Range, Cells, etc.) are 'objects' in the interface.  But just casting the result to your desired interface (like you did with Excel.Application above) will get you intellisense again.
Reply all
Reply to author
Forward
0 new messages