次の方法で共有


Window.CommandBars プロパティ

定義

オブジェクトに関連付けられているウィンドウの Microsoft Office CommandBars コレクションへの参照を Window 取得します。

public:
 abstract property System::Object ^ CommandBars { System::Object ^ get(); };
public abstract object CommandBars { get; }
member this.CommandBars : obj
Public MustOverride ReadOnly Property CommandBars As Object

プロパティ値

オブジェクトに関連付Windowけられているウィンドウの Microsoft Office CommandBars コレクションへの参照。

例外

フォーム テンプレートが、[フォームのオプション] ダイアログ ボックスの [セキュリティと信頼] カテゴリを使用して [完全信頼] として構成されていません。

次の例では、 クラスの WindowCommandBars プロパティを使用して CommandBars コレクションを取得し、コマンド バーの数を表示します。

この例を使用するには、フォーム コード モジュールの宣言セクションに Microsoft.Office.Core 名前空間の using または Imports ディレクティブが必要です。

// Get CommandBars collection casting to 
// Microsoft.Office.Core.CommandBars type.
CommandBars myCommandBars = 
   (CommandBars)this.Application.ActiveWindow.CommandBars;

// Get count using CommandBars Count property.
int commandBarsCount = myCommandBars.Count;

// Display count of command bars.
MessageBox.Show("There are " + commandBarsCount.ToString() + 
   " Command Bars");
' Get CommandBars collection casting to 
' Microsoft.Office.Core.CommandBars type.
Dim myCommandBars As CommandBars = 
   DirectCast(Me.Application.ActiveWindow.CommandBars, CommandBars)

' Get count using CommandBars Count property.
Dim commandBarsCount As Integer = myCommandBars.Count

' Display count of command bars.
MessageBox.Show("There are " & commandBarsCount.ToString() & 
   " Command Bars")

注釈

CommandBars コレクションへの参照を確立した後は、このクラスのすべてのプロパティおよびメソッドにアクセスできます。

重要: CommandBars プロパティを機能させるには、Visual Studio 2012 の [参照の追加] ダイアログ ボックスの [COM] タブを使用して、Microsoft Office 14.0 オブジェクト ライブラリへの参照を確立する必要があります。 これにより、CommandBars クラスを含む Microsoft.Office.Core 名前空間への参照が確立されます。 さらに、フォームは完全信頼として実行されている必要があります。

このメンバーには、[フォームのオプション] ダイアログ ボックスの [セキュリティ] または [信頼] カテゴリを使用して、完全な信頼を与えられて実行するように構成されたフォーム テンプレートから開かれたフォームのみがアクセスできます。 このメンバーは、直接の呼び出し側の完全な信頼が必要であり、部分的に信頼されたコードでは使用できません。 詳細については、MSDN の「部分信頼コードからのライブラリの使用」を参照してください。

この型またはメンバーには、Microsoft InfoPath Filler で開いたフォームで実行されるコードからのみアクセスできます。

適用対象