(Solved) – How to correctly pass an argument from an inbuilt Office enum from Ribbon to VBA Macro?

  • by
(solved)-–-how-to-correctly-pass-an-argument-from-an-inbuilt-office-enum-from-ribbon-to-vba-macro?

I’m using PowerPoint extensively in multiple languages, and I have a macro that changes the language of each box across the presentation. I call the macro with an argument from the Ribbon, passing the argument as a Tag (as I haven’t found any other working method, I can’t just call sub(argument) in the Ribbon XML). The problem is, that it only works, when I use an explicit numeric argument (ID of a language), and can’t use the name from msoLanguageID enum.

Ribbon XML:

Control Sub:

Public Sub langChange(control As IRibbonControl)
    Call Macros.ChangeSpellCheckLang(control.Tag)
End Sub

And the final procedure:

Sub ChangeSpellCheckLang(lang As Integer)
(...)
.Text.Range.LanguageID = lang
End Sub

This works, but if I change the tag from 2057 to msoLanguageIDEnglishUK I get an error (13) Type mismatch. I tried changing the final procedure to lang as String or Variant, but I keep getting the same error. I know that msoLanguageIDEnglishUK would work, as previously my final procedure didn’t use an argument – instead I just explicitly set …Text.Range.LanguageID = msoLanguageIDEnglishUK and it worked.

So, how can I avoid hardcoding language IDs, while still being able to pass them as arguments for the procedure from the Ribbon?

Leave a Reply

Your email address will not be published. Required fields are marked *