次の方法で共有


方法 : Word の組み込みダイアログ ボックスを使用する

更新 : 2007 年 11 月

対象

このトピックの情報は、指定された Visual Studio Tools for Office プロジェクトおよび Microsoft Office のバージョンにのみ適用されます。

プロジェクトの種類

  • ドキュメント レベルのプロジェクト

  • アプリケーション レベルのプロジェクト

Microsoft Office のバージョン

  • Word 2003

  • Word 2007

詳細については、「アプリケーションおよびプロジェクトの種類別の使用可能な機能」を参照してください。

Microsoft Office Word の使用時に、ユーザー入力用のダイアログ ボックスを表示する必要があることがあります。独自のダイアログ ボックスを作成することもできますが、Word の組み込みダイアログ ボックスを使用することもできます。Word の組み込みダイアログ ボックスは、Application オブジェクトの Dialogs コレクションで公開されています。この方法を利用すると、列挙体で表される 200 以上の組み込みダイアログ ボックスにアクセスできます。

組み込みダイアログ ボックスを使用するには

  1. 変数に WdWordDialog 列挙体の値のいずれかを使用して、表示する Word ダイアログ ボックスを表す Dialog オブジェクトを作成します。次のコード例を使用するには、プロジェクトの ThisDocument クラスまたは ThisAddIn クラスから実行します。

    Dim dlg As Word.Dialog = Application.Dialogs.Item(Word.WdWordDialog.wdDialogFileNew)
    
    Word.Dialog dlg = Application.Dialogs[Word.WdWordDialog.wdDialogFileNew];
    
  2. Dialog 変数を作成したら、そのメソッドを呼び出すことができます。

    dlg.Show()
    
    object timeOut = 0;
    dlg.Show(ref timeOut);
    

ダイアログ ボックスのメンバにアクセスするには

  1. ダイアログ ボックスの種類を取得し、Name プロパティを Testing に設定します。次のコード例を使用するには、プロジェクトの ThisDocument クラスまたは ThisAddIn クラスから実行します。

    ahzbkf8e.alert_note(ja-jp,VS.90).gifメモ :

    組み込み Word ダイアログ ボックスとの対話は、遅延バインディングを通じて行われます。したがって、Option Strict を On に設定したり、C# を使用したりした場合は、ダイアログ ボックスのメンバに直接アクセスできません。ダイアログ ボックスのメンバにアクセスするには、Reflection ライブラリを使用する必要があります。

    Dim dlg As Word.Dialog = Application.Dialogs(Word.WdWordDialog.wdDialogFileOpen)
    Dim dlgType As Type = GetType(Word.Dialog)
    
    ' Set the Name property of the dialog box.
    dlgType.InvokeMember("Name", _
        Reflection.BindingFlags.SetProperty Or _
            Reflection.BindingFlags.Public Or _
            Reflection.BindingFlags.Instance, _
        Nothing, dlg, New Object() {"Testing"}, _
        System.Globalization.CultureInfo.InvariantCulture)
    
    Word.Dialog dlg = Application.Dialogs[Word.WdWordDialog.wdDialogFileOpen];
    System.Type dlgType = typeof(Word.Dialog);
    
    // Set the Name property of the dialog box.
    dlgType.InvokeMember("Name", 
        System.Reflection.BindingFlags.SetProperty | 
            System.Reflection.BindingFlags.Public | 
            System.Reflection.BindingFlags.Instance,
        null, dlg, new object[] {"Testing"},
        System.Globalization.CultureInfo.InvariantCulture);
    
  2. ダイアログ ボックスを表示し、メッセージ ボックスに Name プロパティを表示します。

    ' Display the dialog box.
    dlg.Show()
    
    ' Show the Name property.
    MessageBox.Show(dlgType.InvokeMember("Name", _
        Reflection.BindingFlags.GetProperty Or _
            Reflection.BindingFlags.Public Or _
            Reflection.BindingFlags.Instance, _
        Nothing, dlg, Nothing, _
        System.Globalization.CultureInfo.InvariantCulture))
    
    // Display the dialog box.
    dlg.Show(ref missing); 
    
    // Show the Name property.
    MessageBox.Show(dlgType.InvokeMember("Name",
        System.Reflection.BindingFlags.GetProperty |
            System.Reflection.BindingFlags.Public |
            System.Reflection.BindingFlags.Instance,
        null, dlg, null,
        System.Globalization.CultureInfo.InvariantCulture).ToString());
    

参照

処理手順

方法 : Word のダイアログ ボックスを非表示モードで使用する

概念

Word オブジェクト モデルの概要

Office ソリューションの省略可能なパラメータについて