Modifica

Condividi tramite


Window2.CommandBars Property

Definition

Gets a reference to the Microsoft Office CommandBars collection contained in the window that is associated with the WindowObject object.

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

Property Value

Implements

Examples

Note: The following example requires a reference to the System.Reflection namespace.

BindingFlags flags = BindingFlags.GetProperty | BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance;

// The CommandBars collection returns only one of the objects 
// that implements an IDispatch interface.
// To perform checks and allow COM-like calls,
// you must create a wrapper by casting to the ObjectWrapper class.
ObjectWrapper commandBars = (ObjectWrapper)thisApplication.ActiveWindow.<span class="label">CommandBars</span>;

int commandBarsCount = (int)commandBars.InvokeByName(
           "Count",    // prop
           flags,
           null,      // arguments
           null);     // Culture

thisXDocument.UI.Alert("There are " + commandBarsCount.ToString() + " Command Bars");

// Either of the following two lines will work
object[] args =  new object[] {1};  
// object[] args =  new object[] {"Standard"};

// This object is outside the wrapper - this gets a .NET object

object commandBarItem = commandBars.InvokeByName(
           "Item",         
           flags,
           args,      // arguments
           null);     // Culture

thisXDocument.UI.Alert("Got the 'Standard' command bar");

string commandBarName = (string)commandBarItem.GetType().InvokeMember(
           "name",
           flags,
           null, 
           commandBarItem, 
           null);

thisXDocument.UI.Alert(commandBarName);

Remarks

The CommandBars collection can be used only by fully trusted forms. If used by a form that is not fully trusted, the CommandBars collection will return a "permission denied" error.

Applies to