Window2.CommandBars Property
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
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.
Important: This member can be accessed only by forms opened from a form template that has been configured to run with full trust using the Security and Trust category of the Form Options dialog box. This member requires full trust for the immediate caller and cannot be used by partially trusted code. For more information, see "Using Libraries from Partially Trusted Code" on MSDN.