ExcelDna and Windows Form Application in C#

1,980 views
Skip to first unread message

Emmanuel GUIGNIER

unread,
Jul 6, 2015, 2:39:35 PM7/6/15
to exce...@googlegroups.com
Hello everybody,

I am new to ExcelDna.
I tried successfuly few examples.

I would like to know if it is possible to build a "Windows Form application" in C# which can be connected with Excel using ExcelDna, and not only a Library ?
Perhaps is possible to introduce forms in a Library ?? (I don't know).

My purpose is to obtain an Excel Workbook in which the end-user can draw manualy some shapes for example and setup data, and manage those shapes and data dynamicaly from a windows form application; those two applications (WForm and Excel) working together.
Thus, the user can work,  at the same time,  within Excel and the window form application.

Sorry for my bad english.
Thanks for your help, due to your greater experience.

Emmanuel 

Govert van Drimmelen

unread,
Jul 7, 2015, 5:30:29 PM7/7/15
to exce...@googlegroups.com, e.gui...@free.fr
Hi Emmanuel,

If you just want to make an external application that automates and interacts with Excel, you do not need Excel-DNA. You can just reference the COM interop assembly for Excel (Microsoft.Office.Interop.Excel) and use the COM object model to talk to Excel.

Inside an Excel add-in (which you might make with Excel-DNA) you could either create a form or a user control which you host in a Custom Task Pane.
For an example of using a form that interacts with Excel, you might have a look at this example: https://github.com/Ron-Ldn/DotNetRefEdit

There are some basic CTP examples in the Excel-DNA distribution.

-Govert

James Faix

unread,
Jul 7, 2015, 11:54:32 PM7/7/15
to exce...@googlegroups.com
Govert's right (as usual). 

You need to
1. Add a project reference to the "Microsoft Excel 15.0 Object Library" (or 14.0, etc) library.
2. Import the Microsoft.Office.Interop.Excel namespace. 
3. Get an object reference to an instance of Excel in your program, from the type Microsoft.Office.Interop.Excel.  (Make sure to specify the namespace to avoid conflicts with System.Windows.Forms.Application.)

It's handy to keep a static Application instance somewhere accessible, like Program.cs, and reference that throughout the program.

You can launch a new Excel instance using the Application constructor:

public static Microsoft.Office.Interop.Excel.Application app = new Microsoft.Office.Interop.Excel.Application();

You can get a reference to an existing Excel instance with System.Diagnostics.Process.  (Although it can be tricky in some situations.)  Like this:

Process xlProcess = Process.GetProcessesByName("EXCEL")[0];

The Process method can have issues in situations with multiple instances of Excel, multiple users with instances of Excel, or restricted security permissions.



Govert van Drimmelen

unread,
Jul 8, 2015, 2:46:28 AM7/8/15
to exce...@googlegroups.com
And just to add to that:

If you are doing this inside an Excel-DNA add-in, you'd get hold of the right Application object by calling

    Microsoft.Office.Interop.Excel.Application app  = (Microsoft.Office.Interop.Excel.Application)ExcelDnaUtil.Application;

-Govert



From: exce...@googlegroups.com [exce...@googlegroups.com] on behalf of James Faix [jamest...@gmail.com]
Sent: 08 July 2015 05:54 AM
To: exce...@googlegroups.com
Subject: [ExcelDna] Re: ExcelDna and Windows Form Application in C#

--
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 post to this group, send email to exce...@googlegroups.com.
Visit this group at http://groups.google.com/group/exceldna.
For more options, visit https://groups.google.com/d/optout.

Emmanuel GUIGNIER

unread,
Jul 13, 2015, 4:14:50 AM7/13/15
to exce...@googlegroups.com
Thanks a lot for your answers !!
It works fine !!
Emmanuel

Manh Nguyen Van

unread,
Aug 23, 2019, 5:54:30 AM8/23/19
to Excel-DNA
Hi Gorvert
please to help to build project DoNotRefEdit in VB.Net language as https://github.com/Ron-Ldn/DotNetRefEdit
sorry for I don't knowlage in C#
thanks in advance

Vào 04:30:29 UTC+7 Thứ Tư, ngày 08 tháng 7 năm 2015, Govert van Drimmelen đã viết:
Reply all
Reply to author
Forward
0 new messages