XL97: WE1183: "Personalizar barras de menu, menus e itens de menu"

IMPORTANTE: Este artigo foi traduzido por um sistema de tradução automática (também designado por Machine translation ou MT), não tendo sido portanto revisto ou traduzido por humanos. A Microsoft tem artigos traduzidos por aplicações (MT) e artigos traduzidos por tradutores profissionais. O objectivo é simples: oferecer em Português a totalidade dos artigos existentes na base de dados do suporte. Sabemos no entanto que a tradução automática não é sempre perfeita. Esta pode conter erros de vocabulário, sintaxe ou gramática… erros semelhantes aos que um estrangeiro realiza ao falar em Português. A Microsoft não é responsável por incoerências, erros ou estragos realizados na sequência da utilização dos artigos MT por parte dos nossos clientes. A Microsoft realiza actualizações frequentes ao software de tradução automática (MT). Obrigado.

Clique aqui para ver a versão em Inglês deste artigo: 166755
Este artigo foi arquivado. Este artigo é oferecido "tal como está" e deixará de ser actualizado.
Sumário
A nota de aplicação "Personalizar barras de menu, menus e itens de menu" (WE1183) está agora disponível a partir do suporte técnico da Microsoft. Nota Esta aplicação pode ajudar a obter informações técnicas para escrever o Visual Basic for Applications código para personalizar menus no Microsoft Excel 97. Nota Esta aplicação destina-se a ser utilizado como um suplemento para o capítulo 8 ("menus e barras de ferramentas") do "Guia do programador Microsoft Office 97/Visual Basic". Notas de aplicações contém exemplos de código que pode executar. Podem ser utilizados nestes exemplos de código com os seguintes elementos: barras de menus, menus, itens de menus, submenus e menus de atalho.

Para obter esta nota de aplicação

O ficheiro seguinte está disponível para transferência a partir do Centro de transferências da Microsoft:
Para obter informações adicionais sobre como transferir ficheiros de suporte da Microsoft, clique no número de artigo que se segue para visualizar o artigo na Microsoft Knowledge Base:
119591Como obter ficheiros de suporte da Microsoft a partir de serviços on-line
Microsoft procedeu de vírus neste ficheiro. Microsoft utilizou o mais recente software de detecção de vírus que estava disponível na data em que o ficheiro foi publicado. O ficheiro é alojado em servidores com segurança avançada que o ajudam a impedir alterações não autorizadas ao ficheiro.
Mais Informação

O texto de We1183

                             TABLE OF CONTENTS                             =================Overview   Using the Examples in This Application NoteVisual Basic for Applications Code Examples and Tips   Command Bars   Control Constants   Menu Bars      Returning an ID for a Command Bar Control      Saving the Active State (for Built-in or Customized Menu Bars)      Creating a Custom Command Bar      Displaying a Custom Command Bar      Deleting a Custom Command Bar      Hiding a Command Bar      Displaying a Command Bar      Restoring a Built-in Command Bar   Menus      Adding a Custom Menu Control to a Command Bar      Disabling a Menu Control on a Command Bar      Enabling a Menu Control on a Command Bar      Deleting a Menu Control on a Command Bar      Restoring a Menu Control on a Command Bar   Menu Items      Adding a Separator Bar to a Menu Control      Creating a Custom Menu Item Control on a Menu      Placing a Check Mark Next to a Menu Item Control      Disabling a Menu Item Control on a Command Bar      Enabling a Menu Item Control on a Command Bar      Deleting a Menu Item Control on a Menu      Restoring a Built-in Menu Item Control on a Menu   Submenus      Adding a Submenu      Adding a Menu Item to a Submenu      Disabling a Menu Item Control on a Submenu      Deleting a Command on a Submenu      Disabling a Submenu Control      Deleting a Submenu Control   Shortcut Menu Bars      Creating a New Shortcut Menu Bar   Shortcut Menus      Creating a Menu Item on a Shortcut Menu Bar      Disabling a Menu Item Control on a Shortcut Menu Bar      Deleting a Menu Item on a Shortcut Menu Bar      Deleting a Shortcut Menu Bar      Restoring a Menu Item on Built-in Shortcut Menu Bar   Submenus on Shortcut Menus      Creating a New Submenu on a Shortcut Menu Bar      Creating a Menu Item Control on a Submenu Located on a Shortcut Menu      Bar      Disabling a Submenu Item Control on a Shortcut Menu      Deleting a Submenu Item Control on a Shortcut Menu      Disabling a Submenu Control on a Shortcut Menu      Deleting a Submenu Control on a Shortcut MenuWhere to Find More Information   The Object Browser   Microsoft Knowledge Base      Using the Microsoft Knowledge Base on the World Wide Web      Using the Microsoft Knowledge Base on The Microsoft Network                                 OVERVIEW                                 ========To perform many of the common tasks that are associated with customizingmenu bars and menus in Microsoft Excel 97 for Windows, use the Customizedialog box (click Customize on the Tools menu). To perform more advancedtasks, or to tailor menu bars and menus for a custom application, you maywant to create Visual Basic for Applications procedures.For more information about using the Customize dialog box, click the OfficeAssistant, type "customize menubar" (without the quotation marks), clickSearch, and then click to view a topic.This Application Note can help you learn techniques for writing VisualBasic for Applications code for customizing menu bars, menus, menu items,submenus, and shortcut menus.Microsoft provides examples of Visual Basic for Applications procedures forillustration only, without warranty either expressed or implied, including,but not limited to the implied warranties of merchantability and/or fitnessfor a particular purpose. The Visual Basic procedures in this article areprovided 'as is' and Microsoft does not guarantee that they can be used inall situations. While Microsoft Support professionals can help explain thefunctionality of a particular macro, they will not modify these examples toprovide added functionality, nor will they help you construct macros tomeet your specific needs. If you have limited programming experience, youmay want to consult one of the Microsoft Solution Providers. SolutionProviders offer a wide range of fee-based services, including creatingcustom macros. For more information about Microsoft Solution Providers,call Microsoft Customer Information Service at (800) 426-9400.                USING THE EXAMPLES IN THIS APPLICATION NOTE                ===========================================The examples in this Application Note use Visual Basic for Applicationscode in Microsoft Excel 97 to customize menus. To use the example macros,follow these steps:1. In Microsoft Excel 97, open the Visual Basic Editor. To do this, point   to Macros on the Tools menu and click Visual Basic Editor (or press   ALT+F11).2. In the Visual Basic Editor, insert a Visual Basic module sheet. To do   this, click Module on the Insert menu.3. Type one of the macro examples from this Application Note. If you   downloaded this document from an online location, you can copy and paste   the example directly into a module sheet. You can then run the example   in the workbook.4. To run a macro, point to Macro on the Tools menu, and then click Macros.   In the Macro dialog box, click the macro name and click Run.           VISUAL BASIC FOR APPLICATIONS CODE EXAMPLES AND TIPS           ====================================================Command Bars------------In Microsoft Excel 97, menu bars and toolbars are referred to as the sameprogrammable object type, the CommandBar object. Within the CommandBarobject are the controls that you use to refer to menus, menu items,submenus, and shortcut menus. With each control, you use a constant in theType argument to specify which type of control to use for the menu,submenu, or menu item. For example, the MsoControlButton constant refers tomenu items on menus. This Application Note discusses customizing andcontrolling command bar menus using Visual Basic for Applications.Control Constants-----------------The following is a list of the various control constants that specify thetype of graphical control to use for a particular menu bar control:MsoControlButton               MsoControlGraphicDropdownMsoControlButtonDropdown       MsoControlGraphicPopupMsoControlButtonPopup          MsoControlGridMsoControlComboBox             MsoControlLabelMsoControlCustom               MsoControlOCXDropDownMsoControlDropdown             MsoControlPopupMsoControlEdit                 MsoControlSplitButtonMRUPopupMsoControlExpandingGrid        MsoControlSplitButtonPopupMsoControlGauge                MsoControlSplitDro pdownMsoControlGenericDropdown      MsoControlSplitExpandingGridMsoControlGraphicComboManipulating menus in Microsoft Excel primarily involves using theconstants MsoControlButton (menu commands), MsoControlPopUp (menus), andMsoBarPopup (shortcut menu bars). For a graphical explanation of eachconstant, click the Office Assistant in the Visual Basic Editor, type"property" (without the quotation marks), click Search, and then click toview the "Type Property (Microsoft Office Reference)" topic.Menu Bars---------A menu bar, which is a kind of command bar, is the kind of object on whichyou add menus, menu items, and submenus.The Office Assistant in Microsoft Office Visual Basic Help can help youfind information about the topics in the following table.   For Information About This Topic              Search for   -------------------------------------------------------------   To add a new menu bar                         Add menubar   To activate a created or built-in menu bar    Show menubar   To delete a custom menu bar                   Delete menubar   To determine whether a menu is built-in       Builtin menubar   To restore all built-in menu bars, menus,     Restore menubar   and menu itemsThe built-in menu bars that are included in Microsoft Excel 97 are listedin the following table.   Built-in Menu Bar             Description   ------------------------------------------------------------------------   Worksheet menu bar            The menu bar that appears when a worksheet                                 is activated   Chart menu bar                The menu bar that appears when a chart                                 sheet or a chart object is selectedReturning an ID for a Command Bar Control:Each command bar control has a unique ID. To return an ID for a control,use a macro.This following example returns the ID for the Tools menu control on theChart menu bar:   Sub Id_Control ()   Dim myId as Object      set myId = CommandBars("Chart Menu Bar").Controls("Tools")      MsgBox myId.Caption & Chr(13) & MyId.Id   End SubFor additional information, please see the following article in theMicrosoft Knowledge Base:   ARTICLE-ID: Q159466   TITLE     : XL97: List of ID Numbers for Built-In Command Bar ControlsSaving the Active State (for Built-in or Customized Menu Bars):You may want to declare OriginalMenuBar a public variable so that asubroutine can use it in an another subroutine, such as an Auto_Closesubroutine. Declaring and using the variable this way resets the user'sprevious menu bar to its original state. The following sample macro resetsthe menu bar:   Public OriginalMenuBar as Object   Sub MenuBars_Capture()      Set OriginalMenuBar = CommandBars.ActiveMenuBar   End SubThe following sample macro recovers the captured menu bar:   Sub MenuBars_Recover()      OriginalMenuBar.Visible = True   End SubDetermining the Name of the Active Menu Bar:The following sample macro returns the name of the active menu bar:   Sub MenuBars_GetName()      MsgBox CommandBars.ActiveMenuBar.Name   End SubCreating a Custom Command Bar:The following example creates a custom command bar named My Command Bar:   Sub MenuBar_Create()      Application.CommandBars.Add Name:="My command bar"   End SubNOTE: The command bar is empty because no controls were added to it. Itdoes not appear until you display it.Displaying a Custom Command Bar:The following example creates and then displays a custom My Custom Bar menubar, and then replaces the built-in menu bar:   Sub MenuBar_Show()   Dim myNewBar as Object      ' Setting the menubar property to True replaces the built-in menu      ' bar.      Set myNewBar = CommandBars.Add (Name:="My Custom Bar", MenuBar:=True)      ' You must first enable your custom menu bar before you make it      ' visible.      ' Enabling a menu bar adds it to the list of available menu bars on      ' the Customize dialog box.      MyNewBar.Enabled = True      MyNewBar.Visible = True   End SubNOTE: The menu bar is empty because no controls were added to it. See the"Menu Items" section for examples that add controls to menu bars.Deleting a Custom Command Bar:The following example deletes the custom menu bar named My Custom Bar thatyou created in the previous example:   Sub MenuBar_Delete()      CommandBars("My Custom Bar").Delete   End SubNOTE: You can only disable built-in command bars; you cannot delete them.Hiding a Command Bar:The following example hides the built-in Worksheet menu bar:   Sub MenuBar_Disable()      CommandBars("Worksheet Menu Bar").Enabled = False   End SubDisplaying a Command Bar:The following example displays the built-in Worksheet menu bar:   Sub MenuBar_Display()      CommandBars("Worksheet Menu Bar").Enabled = True   End SubRestoring a Built-in Command Bar:Restoring a menu bar resets the default controls (menus and menu items).The following example restores the built-in Worksheet menu bar:   Sub MenuBar_Restore()      CommandBars("Worksheet Menu Bar").Reset   End SubNOTE: You can reset only built-in menu bars; you cannot reset a custom menubar.Menus-----You can add menus to a custom or built-in menu bar.The Office Assistant in Microsoft Office Visual Basic Help can help youfind information about the topics in the following table.   For Information About This Topic              Search for   ----------------------------------------------------------   To add a menu to the worksheet menu bar       Add menu   To delete a menu from the worksheet menu bar  Delete menu   To restore a deleted built-in menu on the     Builtin menu   worksheet menu bar   To disable a menu on the worksheet menu bar   Disable menuAdding a Custom Menu Control to a Command Bar:The following example adds the myMenu menu to the Worksheet menu bar:   Sub Menu_Create()   Dim myMnu As Object      Set myMnu = CommandBars("worksheet menu bar").Controls. _         Add(Type:=msoControlPopup, before:=3)      With myMnu      ' The "&" denotes a shortcut key assignment (Alt+M in this case).         .Caption = "my&Menu"      End With   End SubDisabling a Menu Control on a Command Bar:A menu that is disabled appears dimmed and is not available.The following example disables the File menu:   Sub Menu_Disable()      CommandBars("Worksheet menu bar").Controls("File").Enabled = False   End SubEnabling a Menu Control on a Command Bar:The following example enables the File menu that you disabled in theprevious example:   Sub Menu_Enable()      CommandBars("Worksheet menu bar").Controls("File").Enabled = True   End SubDeleting a Menu Control on a Command Bar:The following example deletes the Help menu from the Worksheet menu bar:   Sub Menu_Delete()      CommandBars("Worksheet menu bar").Controls("Help").Delete   End SubRestoring a Menu Control on a Command Bar:To restore a menu control, you must know the identification (ID) number forthe control. To determine the ID number, see the "Returning an ID for aCommand Bar Control" section.The following example restores the Help menu on the Worksheet menu bar:   Sub Menu_Restore()   Dim myMnu As Object      Set myMnu = CommandBars("Worksheet menu bar")      ' Id 30010 refers to the Help menu control.      myMnu.Controls.Add Type:=msoControlPopup, Id:=30010, before:=10      myMnu.Reset   End SubMenu Items----------You can add menu item controls to or remove them from built-in or custommenu controls on command bars. Each command bar control has a uniqueidentification number (ID). An ellipsis (...) that follows a menu itemcaption denotes a menu item that opens a dialog box. Menu items with asmall, black arrow after the caption display one or more submenu items.The Office Assistant in Microsoft Office Visual Basic Help can help youfind information about the topics in the following table.   For Information About This Topic              Search for   ----------------------------------------------------------   To add a menu item to an existing worksheet   Add menuitem   menu   To delete a menu item                         Delete menuitem   To disable a custom menu item                 Disable menuitemAdding a Separator Bar to a Menu Control:A separator bar is a horizontal line that separates menu commands on amenu.The following example adds a separator bar before the Worksheet command onthe Insert menu:   Sub menuItem_AddSeparator()      CommandBars("Worksheet menu bar").Controls("Insert") _      .Controls("Worksheet").BeginGroup = True   End SubNOTE: To remove a separator bar, set the BeginGroup property to False.Creating a Custom Menu Item Control on a Menu:The following example creates a new command called Custom1 on the Toolsmenu of the Worksheet menu bar, and then runs the macro Code_Custom1 whenyou click Custom1:   Sub menuItem_Create()      With CommandBars("Worksheet menu bar").Controls("Tools")         .Controls.Add(Type:=msoControlButton, Before:=1).Caption = _         "Custom1"         .Controls("Custom1").OnAction = "Code_Custom1"      End With   End SubNOTE: This is the code that runs when you click Custom1.   Sub Code_Custom1()      MsgBox "you clicked Custom1"   End SubPlacing a Check Mark Next to a Menu Item Control:The following example places a check mark next to the Custom1 command if itis not selected and removes the check mark if it is selected:   Sub menuItem_checkMark()   Dim myPopup as Object      Set myPopup = CommandBars("Worksheet menu bar").Controls("Tools")      If myPopup.Controls("Custom1").State = msoButtonDown Then         ' Remove check mark next to menu item.         myPopup.Controls("Custom1").State = msoButtonUp         MsgBox "Custom1 is now unchecked"         Else           ' Add check mark next to menu item.            myPopup.Controls("Custom1").State = msoButtonDown            MsgBox "Custom1 is now checked"       End If      End SubDisabling a Menu Item Control on a Command Bar:Menu items that are disabled appear dimmed and are not available.The following example disables the Custom1 menu item that you created onthe Tools menu:   Sub MenuItem_Disable()   Dim myCmd as Object      Set myCmd = CommandBars("Worksheet menu bar").Controls("Tools")      myCmd.Controls("Custom1").Enabled = False   End SubEnabling a Menu Item Control on a Command Bar:The following example enables the Custom1 menu item that you disabled inthe previous example:   Sub MenuItem_Enable()   Dim myCmd as Object      Set myCmd = CommandBars("Worksheet menu bar").Controls("Tools")      myCmd.Controls("Custom1").Enabled = True   End SubDeleting a Menu Item Control on a Menu:The following example deletes the Save menu item on the File menu:   Sub menuItem_Delete()   Dim myCmd as Object      Set myCmd = CommandBars("Worksheet menu bar").Controls("File")      MyCmd.Controls("Save").Delete   End SubRestoring a Built-in Menu Item Control on a Menu:To restore a menu item control, you must know the identification (ID)number for the control. To determine the ID number, see the "Returning anID for a Command Bar Control" section.The following example restores the Save menu item that you deleted in theprevious example:   Sub menuItem_Restore()   Dim myCmd as Object      Set myCmd = CommandBars("Worksheet menu bar").Controls("File")      ' Id 3 refers to the Save menu item control.      myCmd.Controls.Add Type:=msoControlButton, Id:= 3, Before:=5   End SubSubmenus--------Submenus appear to the side of the parent menu when you click a menu item.A menu item that is a submenu control has a small black arrow located atthe right end of the menu item name.Adding a Submenu:The following example adds a new submenu named NewSub to the Tools menu onthe Worksheet menu bar:   Sub SubMenu_Create()   Dim newSub as Object      Set newSub = CommandBars("Worksheet menu bar").Controls("Tools")      With newSub         .Controls.Add(Type:=msoControlPopup, Before:=1).Caption="NewSub"      End With   End SubAdding a Menu Item to a Submenu:This example adds a new menu item named SubItem1 to the NewSub submenu, andthen runs the Code_SubItem1 macro when you click SubItem1:   Sub SubMenu_AddItem()   Dim newSubItem as Object      Set newSubItem = CommandBars("Worksheet menu bar") _      .Controls("Tools").Controls("NewSub")      With newSubItem         .Controls.Add(Type:=msoControlButton, Before:=1).Caption = _         "SubItem1"         .Controls("SubItem1").OnAction = "Code_SubItem1"      End With   End SubThe following is the macro code that runs when you click SubItem1:   Sub Code_SubItem1()      MsgBox "you clicked SubItem1"   End SubDisabling a Menu Item Control on a Submenu:Menu items that are disabled appear dimmed and are not available.The following example disables the SubItem command that you created in theprevious example:   Sub SubMenu_DisableItem()      CommandBars("Worksheet menu bar").Controls("Tools") _      .Controls("NewSub").Controls("SubItem1").Enabled = False   End SubNOTE: To enable the disabled control, set the Enabled property to True.Deleting a Command on a Submenu:The following example deletes the SubItem1 command that you created on theNewSub submenu:   Sub SubMenu_DeleteItem()      CommandBars("Worksheet menu bar").Controls("Tools") _      .Controls("NewSub").Controls("SubItem1").Delete   End SubDisabling a Submenu Control:Submenus that are disabled appear dimmed and are not available.The following example disables the NewSub submenu that you created on theTools menu:   Sub SubMenu_DisableSub()      CommandBars("Worksheet menu bar").Controls("Tools") _      .Controls("NewSub").Enabled = False   End SubNOTE: To enable the disabled control, set the Enabled property to True.Deleting a Submenu Control:The following example deletes the NewSub submenu that you created on theTools menu:   Sub SubMenu_DeleteSub()      CommandBars("Worksheet menu bar").Controls("Tools") _      .Controls("NewSub").Delete   End SubShortcut Menu Bars------------------Shortcut menu bars appear when you use the right mouse button to click aspecific Microsoft Excel object. Microsoft Excel has many shortcut menubars for which a variety of menus are available. You can also create customshortcut menu bars and customize the built-in menu bars. The onlydifference between shortcut menus and other menu bars is that when youcreate the shortcut menu using the Add method, you must specify themsoBarPopUp constant as the Position argument. Use the ShowPopup method todisplay shortcut menus, as demonstrated in the previous examples. You canassign event procedures for user actions, for example, to display ashortcut menu in response to a right-click event.The shortcut menu bars that are available in Microsoft Excel are asfollows:   &Wizard            Document                   Query and Pivot   ActiveX Control    Excel Control              Query Layout   AutoCalculate      Floor and Walls            Rotate Mode   AutoFill           Formula Bar                Row   Built-in Menus     Inactive Chart             Series   Cell               Layout                     Shapes   Chart              Nondefault Drag and Drop   System   Column             Object/Plot                Title Bar (Charting)   Connector          OLE Object                 Trendline   Curve              Pictures Context           Menu WordArt Context Menu   Curve Node         PivotTable Context Menu    Workbook Tabs   Curve Segment      Plot Area                  XLM Cell   Desktop            Ply   Dialog             QueryCreating a New Shortcut Menu Bar:The following example creates a new shortcut menu bar called myShortcutBar:   Sub Shortcut_Create()   Dim myShtCtBar as Object      Set myShtCtBar = CommandBars.Add(Name:="myShortcutBar", _      Position:=msoBarPopup)      ' This displays the shortcut menu bar.      ' 200, 200 refers to the screen position in pixels as x and y   coordinates.      myShtCtBar.ShowPopup 200,200   End SubNOTE: The shortcut menu bar appears empty because no controls (menu itemsor submenus) have been added to it yet.The constant msoBarPopup is used in the Position argument to denote ashortcut menu bar.Shortcut Menus--------------Creating a Menu Item on a Shortcut Menu Bar:The following example creates a new menu command named Item1 on theshortcut menu bar named myShortcutBar and runs the Code_Item1 macro whenyou click Item1:   Sub Shortcut_AddItem()   Dim myBar as Object      Set myBar = CommandBars("myShortcutBar")      With myBar         .Controls.Add (Type:=msoControlButton, before:=1).Caption = _         "Item1"         .Controls("Item1").OnAction = "Code_Item1"      End With      myBar.ShowPopup 200,200   End SubThe following is the macro that runs when you click Item1 on myShortcutBar:   Sub Code_Item1()      MsgBox "you clicked Item1"   End SubDisabling a Menu Item Control on a Shortcut Menu Bar:Menu items that are disabled appear dimmed and are not available.The following example disables the Item1 command that you created in theprevious example:   Sub Shortcut_DisableItem()      Set myBar = CommandBars("myShortcutBar")      myBar.Controls("Item1").Enabled = False      myBar.ShowPopup 200,200   End SubNOTE: To enable the disabled item, set the Enabled property to True.Deleting a Menu Item on a Shortcut Menu Bar:The following example deletes the menu command named Item1 onmyShortcutBar:   Sub Shortcut_DeleteItem()      Set myBar = CommandBars("myShortcutBar")      myBar.Controls("Item1").Delete      myBar.ShowPopup 200,200   End SubDeleting a Shortcut Menu Bar:Deleting the shortcut menu bar removes it and all of its items. You cannotrestore a deleted custom menu bar. To restore it, you must recreate it andall of its menu items, submenus, and so on.The following example deletes the shortcut menu myShortCutBar that youcreated in a previous example:   Sub Shortcut_DeleteShortCutBar()      CommandBars("MyShortCutBar").Delete   End SubRestoring a Menu Item on Built-in Shortcut Menu Bar:You can restore default menu items on built-in menu bars. However, youcannot restore custom menu items. To restore a built-in menu control, youmust know the identification (ID) number for the control. To determine theID number, see the "Returning an ID for a Command Bar Control" section.The following example restores the Cut command on the worksheet Cellshortcut menu bar:   Sub Shortcut_RestoreItem()      ' Id 21 refers to the Help menu control.      CommandBars("Cell").Controls.Add Type:=msoControlButton, Id:21,   Before:=1   End SubSubmenus on Shortcut Menus--------------------------You can create submenus on shortcut menu bars. Submenus appear to the sideof the parent menu when you click a menu item control. A menu item that isa submenu control has a small, black arrow located to the right of itsname.Creating a New Submenu on a Shortcut Menu Bar:The following example adds a new submenu named NewSub on the worksheet Cellshortcut menu:   Sub ShortcutSub_Create()      CommandBars("Cell").Controls.Add(Type:=msoControlPopup, before:=1) _      .Caption = "NewSub"       ' This displays the shortcut menu bar.       ' 200, 200 refers to the screen position in pixels as x and y       ' coordinates.      CommandBars("Cell").ShowPopup 200, 200   End SubNOTE: The submenu is empty because no menu items have been added to it yet.Creating a Menu Item Control on a Submenu Located on a Shortcut Menu Bar:The following macro adds the command subItem1 to the submenu NewSub thatyou created on the Cell shortcut menu, and then runs the Code_subItem1macro when you click subItem1:   Sub ShortcutSub_AddItem()   Dim newSubItem as Object      Set newSubItem = CommandBars("Cell").Controls("NewSub")      With newSubItem         .Controls.Add(Type:=msoControlButton, before:=1).Caption =          "subItem1"         ' This will run the subItem1_Code macro when subItem1 is clicked.         .Controls("subItem1").OnAction = "Code_subItem1"      End With      ' This displays the Cell shortcut menu bar.      ' 200, 200 refers to the screen position in pixels as x and y      ' coordinates      CommandBars("Cell").ShowPopup 200, 200   End SubThe following is the macro that runs when you click subItem1:   Sub subItem1_Code()      MsgBox "you clicked subItem1"   End SubDisabling a Submenu Item Control on a Shortcut MenuMenu items that are disabled appear dimmed and are not available.The following example disables the command subItem1 on the NewSub submenu:   Sub ShortcutSub_DisableItem()      CommandBars("Cell").Controls("NewSub") _      .Controls("subItem1").Enabled = False      ' This displays the Cell shortcut menu bar.      ' 200, 200 refers to the screen position in pixels as x and y      ' coordinates.      CommandBars("Cell").ShowPopup 200, 200   End SubNOTE: To enable a disabled item, set the Enabled property to True.Deleting a Submenu Item Control on a Shortcut Menu:The following example deletes the command subItem1 on the NewSub submenu:   Sub ShortcutSub_DeleteItem()      CommandBars("Cell").Controls("NewSub").Controls("subItem1").Delete      ' This displays the Cell shortcut menu bar.      ' 200, 200 refers to the screen position in pixels as x and y      ' coordinates.      CommandBars("Cell").ShowPopup 200, 200   End SubDisabling a Submenu Control on a Shortcut Menu:Menu items that are disabled appear dimmed and are not available.The following example disables the NewSub submenu on the Cell shortcut menubar:   Sub ShortcutSub_DisableSub()      CommandBars("Cell").Controls("NewSub").Enabled = False      ' This displays the Cell shortcut menu bar.      ' 200, 200 refers to the screen position in pixels as x and y      ' coordinates.      CommandBars("Cell").ShowPopup 200, 200   End SubNOTE: To enable a disabled item, set the Enabled property to True.Deleting a Submenu Control on a Shortcut Menu:Deleting the submenu removes it and all of its items. You cannot restore adeleted custom submenu. To restore it, you must recreate it and all of itsmenu items, submenus, and so on.The following example deletes the NewSub submenu that you created on theCell shortcut menu bar:   Sub ShortcutSub_DeleteSub()      CommandBars("Cell").Controls("NewSub").Delete      ' This displays the Cell shortcut menu bar.      ' 200, 200 refers to the screen position in pixels as x and y      ' coordinates.      CommandBars("Cell").ShowPopup 200, 200   End SubWHERE TO FIND MORE INFORMATION==============================The Object Browser------------------The Object Browser contains a complete list of all of the properties andmethods for a specific menu item. To find this information, switch to theVisual Basic Editor (press ALT+F11), click Object Browser on the View menu(or press F2), type the name of the control in the search box, and thenpress ENTER or click Search.For more information about using the Object Browser, click the OfficeAssistant in the Visual Basic Editor, type "object browser" (without thequotation marks), click Search, and then click to view the "Use the ObjectBrowser" topic.NOTE: If the Assistant is hidden, click the Office Assistant button on theStandard toolbar. If Microsoft Excel Help is not installed on yourcomputer, please see the following article in the Microsoft Knowledge Base:ARTICLE-ID: Q120802TITLE     : Office: How to Add/Remove a Single Office Program or ComponentMicrosoft Knowledge Base------------------------The Microsoft Knowledge Base is a primary Microsoft product informationsource for Microsoft Technical Support professionals. The Microsoft KnowledgeBase is also available to Microsoft customers. This comprehensive databasecontains detailed articles with technical information about Microsoftproducts, documented fix lists, documentation errors, and answers tocommonly asked technical support questions. These articles are availablethrough the World Wide Web, The Microsoft Network, CompuServe*, Genie(tm),and the Microsoft Developer Network compact disc. You can also access theKnowledge Base if you purchase a Microsoft TechNet compact discsubscription.Using the Microsoft Knowledge Base on the World Wide Web:To connect to the Microsoft Knowledge Base on the Web, use the followingaddress   http://support.microsoft.com/supportand follow the detailed instructions on the page.NOTE: Because the Microsoft Web site is regularly updated, the siteaddress may change without notice. If this occurs, link to the Microsofthome page at the following address:   http://www.microsoft.comUsing the Microsoft Knowledge Base on The Microsoft Network:To connect to the Microsoft Knowledge Base, use the following steps:1. On the Edit menu, click Go to.2. Click Other Location.3. When the prompt "Type a Go word for a particular service" appears, type   "mssupport" (without the quotation marks).NOTE: It may take a minute or more for the Microsoft Knowledge Base toappear while it prepares the necessary files to run.4. Double-click MS Knowledge Base.---------------------------------------------------------------------------The disk and software contained on it, including any accompanyingdocumentation (the "Software"), are provided to you at no additionalcharge. Microsoft Corporation owns all rights, title, and interest in andto the Software. The user assumes the entire risk as to the accuracy andthe use of the Software.COPYRIGHT NOTICE. Copyright (c) 1997 Microsoft Corporation. Microsoftand/or its suppliers, One Microsoft Way, Redmond, Washington 98052-6399U.S.A. All rights reserved.TRADEMARKS. Microsoft, Windows, Windows NT, MSN, The Microsoft Networkand/or other Microsoft products referenced herein are either trademarks orregistered trademarks of Microsoft. Other product and company namesmentioned herein may be the trademarks of their respective owners.The names of companies, products, people, characters and/or data mentionedherein are fictitious and are in no way intended to represent any realindividual, company, product or event, unless otherwise noted.NO WARRANTY. THE SOFTWARE IS PROVIDED "AS-IS," WITHOUT WARRANTY OF ANYKIND, AND ANY USE OF THIS SOFTWARE PRODUCT IS AT YOUR OWN RISK. TO THEMAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, MICROSOFT AND ITS SUPPLIERSDISCLAIM ALL WARRANTIES AND CONDITIONS, EITHER EXPRESS OR IMPLIED,INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES AND CONDITIONS OFMERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE, TITLE, AND NON-INFRINGEMENT, WITH REGARD TO THE SOFTWARE.LIMITATION OF LIABILITY. TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW,IN NO EVENT SHALL MICROSOFT OR ITS SUPPLIERS BE LIABLE FOR ANY SPECIAL,INCIDENTAL, INDIRECT, OR CONSEQUENTIAL DAMAGES WHATSOEVER (INCLUDING,WITHOUT LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESSINTERRUPTION, LOSS OF BUSINESS INFORMATION, OR ANY OTHER PECUNIARY LOSS)ARISING OUT OF THE USE OF OR INABILITY TO USE THE SOFTWARE, EVEN IFMICROSOFT HAS BEEN ADVISED OF THE POSSIBLITY OF SUCH DAMAGES. BECAUSE SOMESTATES AND JURISDICTIONS DO NOT ALLOW THE EXCLUSION OR LIMITATION OFLIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES, THE ABOVE LIMITATION MAYNOT APPLY. MICROSOFT'S ENTIRE LIABILITY AND YOUR EXCLUSIVE REMEDY UNDERTHIS EULA SHALL NOT EXCEED FIVE DOLLARS (US$5.00).The following conditions also apply to your use of the Software:The Software may be copied and distributed internally only, subject to thefollowing conditions:All | text must be copied without modification and all pages must beincluded;If software is included, all files on the disk(s) |must be copied withoutmodification [the MS-DOS(R) utility diskcopy is appropriate for thispurpose];All components of this Software must be distributed together; andThis Software may not be distributed to any third party.If you are not a Microsoft Premier customer, Microsoft shall not providetechnical support for this Software.The Software is provided with RESTRICTED RIGHTS.  Use, duplication, ordisclosure by the Government is subject to restrictions set forth insubparagraph (c)(1)(ii) of the Rights in Technical Data and ComputerSoftware clause at DFARS 252.227-7013 or subparagraphs (c)(1) and (2) ofthe Commercial Computer Software-Restricted Rights at 48 CFR 52.227-19, asapplicable.  Manufacturer is Microsoft Corporation, One Microsoft Way,Redmond, WA  98052-6399.  Any transfer of the Software must be accompaniedby this statement and may only be transferred if first approved byMicrosoft.You agree that you will not export or re-export the Software to anycountry, person, entity or end user subject to U.S.A. export restrictions,and you are responsible for complying with all applicable U.S. and localexport laws in connection with the use of this Software.  You warrant andrepresent that neither the U.S.A. Bureau of Export Administration nor anyother federal agency has suspended, revoked or denied you exportprivileges.This EULA is governed by the laws of the State of Washington, U.S.A.				
appnote

Aviso: Este artigo foi traduzido automaticamente

Propriedades

ID do Artigo: 166755 - Última Revisão: 02/09/2014 13:09:52 - Revisão: 2.4

Microsoft Excel 97 Standard Edition

  • kbnosurvey kbarchive kbmt kbdownload kbappnote kbfile kbgraphxlink kbinfo kbprogramming KB166755 KbMtpt
Comentários