Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unknown Function ".Index" in German Excel #4

Closed
markibarki opened this issue Oct 10, 2016 · 6 comments
Closed

Unknown Function ".Index" in German Excel #4

markibarki opened this issue Oct 10, 2016 · 6 comments

Comments

@markibarki
Copy link

In my German Excel version 2016 (16.0.4432.1000, 32-Bit) I get an "Unknown function"-error when I open "Simple Toolkit_DEV.xlam". It should be in menu_lib.bas:47 :
helpMenuIndex = mainMenuBar.Controls(insertBefore).Index

My fix to that is in line 48/49 where I change
Set customMenu = mainMenuBar.Controls.Add(Type:=msoControlPopup, Before:=helpMenuIndex)
to
Set customMenu = mainMenuBar.Controls.Add(Type:=msoControlPopup, Before:=mainMenuBar.Controls.Count)

Now, my Excel shows a new ribbon tab "Add-Ins" with the "Simple Tools (dev)" drop down menu as single element of this tab.

@jimm-domingo
Copy link
Contributor

Thanks @markibarki for reporting this issue. It looks like the error occurs because of the default value for the optional installBefore parameter to the AddCustomMenu procedure in menu_lib.bas (line 42):

Sub AddCustomMenu(menuName As String, definition() As String, _
                  Optional insertBefore As String = "Help")

I suspect the "Help" menu in your German Excel has a different name (caption). So when the code on line 47 tries to find that menu by this default English name, it doesn't find the menu. Therefore, the sub-expression:

 mainMenuBar.Controls(insertBefore)

returns Nothing, which of course, does not have ".Index" function.

To confirm this, could you please restore menu_lib.bas to its original state, and then make this modification to line 36 in menu.bas:

AddCustomMenu myMenuName, definition, "(HELP-MENU-NAME)"

Replace "(HELP-MENU-NAME)" with the name of the Help menu as it appears in your Excel.

@markibarki
Copy link
Author

I have tested your suggestion, but it doesn't work. I got the same error message. I also tried to add a custom menu "Help" (and in German "Hilfe"), but also then I got the same error.

When I run the following code to print the menu names, I got English names also in my German Excel:

Dim vsoCommandBar As CommandBar
For Each vsoCommandBar In Application.CommandBars
    Debug.Print vsoCommandBar.Name
Next

Output:

Worksheet Menu Bar
Chart Menu Bar
WordArt
Picture
Drawing Canvas
[...]
Formula Bar
[...]

There is no item "Help" in the resulting list. But also if I try to use "Formula Bar" it doesn't work. It looks like the function ".Index" is generally not available.

@jimm-domingo
Copy link
Contributor

Sorry @markibarki for the delay in responding. That's interesting that the command bars have English names, but in some way, that does make sense, because then code accessing them would work regardless of language used in the Excel UI (German vs English vs ...).

The "Help" menu is actually a member of the first command bar (the one named "Worksheet Menu Bar"). What output do you get when you enter this code snippet?

Dim menu_bar As CommandBar
Dim menu As CommandBarControl

Set menu_bar = Application.CommandBars("Worksheet Menu Bar")
For Each menu in menu_bar.Controls
    Debug.Print menu.Id, menu.Caption
Next

We might see "Hilfe" in the output.

@markibarki
Copy link
Author

The output of your code is as follows:

 30002        &Datei
 30003        &Bearbeiten
 30004        &Ansicht
 30005        &Einfügen
 30006        Forma&t
 30007        E&xtras
 30011        Date&n
 1            Tea&m
 30009        &Fenster
 30010        &?

If I change your code to AddCustomMenu myMenuName, definition, "&?", then the error is gone. There is, similar to my initial fix, a new ribbon menu "Add-Ins" with the menu content in it.

jimm-domingo added a commit that referenced this issue Nov 1, 2016
Changed the default behavior for finding the Help menu -- we now look it
by its control id (which is language-independent).  This change still
needs to be verified with a non-English version of Excel.
@jimm-domingo
Copy link
Contributor

Thanks @markibarki for the additional information. I suspected that the Id of the "Help" menu (whose caption in your Excel is "&?") was 30010. So as noted above in the referenced commit, I modified the default behavior in the AddCustomMenu function to search for the Help menu by its control id, instead of by its caption.

This change works fine with my English Excel, but it still needs to be tested to see if it works with another language. If you could download the latest pre-release (v1.3.0-rc.1), and check if it works without modification for your German Excel, I'd appreciate that.

@jimm-domingo
Copy link
Contributor

Closing this ticket because I just did the official release of v1.3.0. If this problem re-appears, we can always re-open this ticket then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants