Compartilhar via


Using DDE in C# for Office automation

 

Looking for some code samples how to pass DDE messages from a .NET program I found out that there‘s a great library already in place that facilitates working with DDE: the NDde project from Codeplex: https://ndde.codeplex.com/

However, I just needed to make one call and including a new DLL into my code would have been too much.

So I just created a sample C# program derived from the NDde code that imports only the necessary functions from the Win32 API to pass an Open DDE message to Excel for opening a workbook.

Workbook wb = DDEHelper.OpenWorkbook(_excel, args[0]);

 

Compilation:

 D:\Projects\DDE>csc /r:C:\Windows\assembly\GAC_MSIL\Microsoft.Office.Interop.Excel\14.0.0.0__71e9bce111e9429c\Microsoft.Office.Interop.Excel.dll DDEOpen.cs
  

DDEOpen.cs