[VC2005] Wordを起動する方法

◆概要

この資料は、Microsoft(R) Visual C# で Microsoft Wordを起動する方法について記述しています。Visual Studio 2005/2008/2010で動作確認済みです。

◆Sample

[プロジェクト]-[参照の追加]の[Com]タブでMicorsoft Word xx.x Object Libraryを選択しOKボタンを押します。
xx.xの部分は使用中のWordのバージョン番号になります。Word 2010なら14.0です。

private void button1_Click(object sender, EventArgs e)
        {
            // Wordのインスタンスを作成
            Word.Application app;
            app = new Word.Application();

            //表示する
            app.Visible = true;

            //Documents コレクションのAdd メソッドを使用して、
            //Normal.dot に基づく新しい文書を作成します。
            object missingValue = Type.Missing;
            app.Documents.Add(ref missingValue, ref missingValue,
                ref missingValue, ref missingValue);
        }

 コード ウィンドウの先頭までスクロールします。using ディレクティブの一覧の末尾に次の行を追加します。

using Word = Microsoft.Office.Interop.Word;


▼ページトップへ