Team LiB
Previous Section Next Section

Creating a New Instance of an Office Application

One way to start an Office application is to create an instance of an Office application programmatically. The following example demonstrates how to create an instance of Microsoft Word. Notice that it sets the value of Visible to true. If you do not do this, a copy of Word will start, but you will have no GUI.

Code Example: Creating an Office Application Instance
Start example
using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using Word;

namespace Client.Chapter_19___Office_Integration
{
          class CreatingOfficeApplications
          {
                [STAThread]
                static void Main(string[] args)
                {
                       Word.ApplicationClass MyWord = new Word.ApplicationClass();
                       MyWord.Visible = true;
                       System.Windows.Forms.Application.Run();
                }
         }
}
End example

Team LiB
Previous Section Next Section