Identifying commandbar names in non-English versions of Excel

D

Daniel Klann

Hi everybody,

I use code that adds a button to the 'Cell' commandbar (this is the
commandbar that appears when you right click in a worksheet cell). I want
to ensure that my code will work in all versions of Excel from 97 to 2003
(this has been tested successfully) and in non-English versions of Excel.

Can anyone tell me if the commandbars names are different in non-English
versions? If they are then how would I get a reference to the Cell
commandbar in code? I can't use the Index property as it seems to be
different depending on which version one is using. Also, I thought about
using the FindControl method on one of the Cell commandbar's buttons and
then getting the Parent property. The problem with this is that each button
on the Cell commandbar exists on other commandbars so I can't be sure I'm
getting the right one.

Thanks for any help,

Daniel Klann
 
B

Bob Phillips

Daniel,

Not sure if this is much use to you, but this code prints all the commandbar
names

Dim cb As CommandBar

For Each cb In CommandBars
Debug.Print cb.Name
Next cb

You would need to figure which non-English name matches the English version,
and I assume it will work in non-English apps.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
D

Daniel Klann

Thanks for your reply Bob but that's not what I'm after. I know how to find
the commandbar names in my version and if I had a non-English version of
Excel I could answer this without posting here! I need someone who has a
non-English version of Excel to be able to confirm whether or not
commandbars have the same names as the English version; specifically, is the
worksheet cell context menu called 'Cell'? Or if someone else has had this
issue and knows the answer that would be cool.

Regards,
Dan
 
B

Bob Phillips

Daniel,

I thought that might be the case. I do know that in principle the .Name
property of a CommandBar object should always use its US-English name, as
Commandbars have a LocalName property as well. This is what Help says about
LocalName

Returns the name of a built-in command bar as it's displayed in the language
version of the container application, or returns or sets the name of a
custom command bar

The key word here however is should, as, according to a Stephen Bullen, the
localisation of a few languages (notably Dutch) got carried away and
localised the .Name property of some commandbars.

So you have the worst situation in practice.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
B

Bob Phillips

It also occurred to me since my last post that as Dutch seems to be the
biggest offender, perhaps Ron de Bruin, or another of our Dutch colleagues,
could supply a list of the Dutch names.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
R

Ron de Bruin

If you add this macro to the workbook where you use Bob's code then you can select a
commandbar name and run it to get all the ID numbers from the items that are in the commandbar.

I think you can always use the commandbar names but you must use the Id's for the
items that are in the commandbar

Sub ListMenuInfo()
'Lists Top Menu Item IDs
' Routine influenced by J.Walkenbach
' Gary Brown
' 12/08/2000
' (e-mail address removed)
' www.kinneson.com
'
Dim objTopMenu As Object
Dim strIDs As String
On Error Resume Next
'list each menu item
For Each objTopMenu In CommandBars(ActiveCell.Value).Controls
strIDs = strIDs & Chr(13) & objTopMenu.Caption & _
" - ID: " & _
CommandBars(ActiveCell.Value).Controls(objTopMenu.Caption).ID
Next objTopMenu
MsgBox strIDs
End Sub
 
R

Ron de Bruin

I just test it and all the commandbars names are the same in the
Dutch version.

Use the ID for the items that are in the commandbar(see the macro I posted)
 
R

Ron de Bruin

Strange

If I use the namelocal in dutch for Cell I get Cel
If I run this I get a error

Sub test()
MsgBox Application.CommandBars("Cell").NameLocal
Application.CommandBars("Cel").Enabled = False
End Sub

I must use this in the Dutch version also
Application.CommandBars("Cell").Enabled = False
 
T

Tom Ogilvy

That is the way it should work Ron. It is kind of moot for Cell, but for
the top menu items like File, View and Tools, in a non-English regional
version they display a different name on the menu (.namelocal), but you can
still refer to them by the English name (.name). Stephen was saying that in
some regional versions, the localization team changed the .name property
value and the English name doesn't work. Perhaps they have corrected this
in the later Dutch versions. (which is what you "discovery" would
indicate).

Anyway, top level menus are both commandbars and controls - I believe your
code will get ID's that identify them as controls and would not work in a
Commandbar vice control usage.
 
R

Ron de Bruin

Hi Tom
the top menu items like File, View and Tools, in a non-English regional
version they display a different name on the menu (.namelocal), but you can
still refer to them by the English name (.name).

If I understand you correct this is not always true

In a French version for example instead of Help you see ? in the
Worksheet Menu Bar

You can't use Help in your code
I use the the Findcontrol then to avoid the problem

Set winHelpMenu = Application.CommandBars(1).FindControl(, 30010)
 
D

Daniel Klann

Thanks Tom/Bob/Ron,

It seems as though I might be lucky and in most situations my code will
work. If I do get anyone saying it doesn't then I'll offer a fix based on
what their commandbar name happens to be. For anyone that is interested
here is my project (it's an Excel add-in) :
http://www.danielklann.com/excel/excel_favourites_add-in.htm - just download
the zip file from the link at the bottom of the page.

Regards,
Daniel Klann
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top