Window2.CommandBars Propriété

Définition

Obtient une référence à la collection CommandBars Microsoft Office contenue dans la fenêtre associée à l’objet WindowObject .

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

Valeur de propriété

Implémente

Exemples

Remarque : L’exemple suivant nécessite une référence à l’espace de noms System.Reflection .

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);

Remarques

La collection CommandBars ne peut être utilisée que par des formulaires avec autorisation totale. Si elle est utilisée par un formulaire qui ne dispose pas d'une autorisation totale, la collection CommandBars renvoie une erreur « autorisation refusée ».

Important : ce membre est accessible uniquement par les formulaires ouverts à partir d’un modèle de formulaire configuré pour s’exécuter en toute confiance à l’aide de la catégorie Sécurité et approbation de la boîte de dialogue Options de formulaire. Ce membre nécessite la confiance totale pour l’appelant immédiat et ne peut être utilisé par un code ayant un niveau de confiance partiel. Pour plus d’informations, voir « Utilisation de bibliothèques à partir de code d’un niveau de confiance partiel » sur MSDN.

S’applique à