BUG: CommandBar.Name property localized in VBA editor of Office.

Author: Carlos J. Quintero (Microsoft MVP) Applies to: Microsoft Office 64-bit
Date: September 2012   Microsoft Office 32-bit

This article explains a bug in the commandbars of the VBA editor of localized versions of Microsoft Office.

More information

The CommandBar class has two properties, Name and NameLocal, that should expose its English name and the localized name. However, in localized versions of Microsoft Office, even the Name property is localized. For example, in the Spanish version the Name property of the "Standard" commandbar is "Estándar", rather than "Standard".

This makes difficult for an add-in for the VBA editor of Microsoft Office to add a button to a built-in commandbar since to get the commandbar using VBE.CommandBars.Item(name), it can fail in localized versions of Microsoft Office.

The following code shows the problem. To run it:

  • Use a localized version of Microsoft Office 2010 (although it happens in previous versions too).
  • Go to the "File", "Options..." menu, "Trust Center" section, click the "Trust Center Settings..." button, go to the "Macro Settings" section and check the "Trust access to the VBA project object model" setting.
  • Open the VBA editor (Alt+F11) and create and run the subroutine below.
  • You will notice that the Name property of a commandbar is localized for some commandbars.
Language: VBScript   Copy Code Copy Code (IE only)
Sub ShowNames()

   Dim cmb As CommandBar

   For Each cmb In Me.Application.VBE.CommandBars

      MsgBox "Name: " & cmb.Name & vbCrLf & "NameLocal: " & cmd.NameLocal


End Sub

Related articles