none
vsto: c# change localization of Excel UI objects, e.g. ribbon, at runtime RRS feed

All replies

  • >>>found some threads about changing the localization of windows forms but nothing about doing the same for ribbons or other UI elements of Excel after the AddIn was started/initialized. My.Application.SetCulture is not avaialbe in my VS 2013 (don't know why).<<<

    According to your description, if you want VSTO Add-in to be localized according to the language version of the office product, you could  refer to below code:
    Excel.Application app = this.GetHostItem<Excel.Application>(typeof(Excel.Application), "Application");
    int lcid = app.LanguageSettings.get_LanguageID(Office.MsoAppLanguageID.msoLanguageIDUI);
    Thread.CurrentThread.CurrentUICulture = new CultureInfo(lcid);
    For more information, click here to refer about localize VSTO addin according to the language of the office product

    Disclaimer: This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.
    Tuesday, June 21, 2016 5:30 AM
  • those discussions are about how to set the language of an addin before it's startedup/initialized. I would like to to change the language after that event.

    I want to be able to change the language at any time, on the fly.

     
    • Edited by StefanM83 Tuesday, June 21, 2016 2:40 PM spelling
    Tuesday, June 21, 2016 7:28 AM
  • is there anything like ThisAddIn.Ribbons.collection so I can iterate through it of call a ribbon by ThisAddIn.Ribbons.item(i).

    Wednesday, June 22, 2016 1:29 PM
  • >>>is there anything like ThisAddIn.Ribbons.collection so I can iterate through it of call a ribbon by ThisAddIn.Ribbons.item(i).

    According to your description, you could use Globals class to access the Ribbon in a document-level project or VSTO Add-in project from anywhere in the project.

    For more information, click here to refer about Accessing the Ribbon at Run Time

    In addition about your issue, you maybe could refer to below helpful link:

    https://social.msdn.microsoft.com/Forums/vstudio/en-US/5144a993-c91a-4ec8-a94d-3aa8df64a5cd/vsto-windows-7-visual-studio-2010-word-2007-culture-does-not-match-addin-culture?forum=vsto

    Thursday, June 23, 2016 3:17 AM
  • thx for the reply but I've already came across those entries/posts but they not offering any solution.

    I would like to access the ribbon like that:

     Globals.Ribbons.imte[0];
     Globals.Ribbons.imte[1];
     ...

    or like that

    foreach (Microsoft.Office.Tools.Ribbon.RibbonBase ribbon in ThisRibbonCollection)
    {
        System.Diagnostics.Debug.Print(ribbon.Name);
    }



    • Edited by StefanM83 Thursday, June 23, 2016 6:29 AM
    Thursday, June 23, 2016 6:28 AM
  • Hi StefanM83,

    According to your description, I suggest that you could refer to Ribbon Object Model Overview

    https://msdn.microsoft.com/en-us/library/bb608623.aspx#SettingReadOnlyProperties

    Friday, June 24, 2016 10:23 AM
  • I've already read that but not help yet
    Friday, June 24, 2016 10:32 AM
  • >>>I've already read that but not help yet

    According to your description, you could modify codes like below:
    foreach (Microsoft.Office.Tools.Ribbon.RibbonBase ribbon in Globals.Ribbons)
    {
         System.Diagnostics.Debug.Print(ribbon.Name);
    }
    In addition could you provide more information about your issue, for example sample code, screenshot etc., that will help us reproduce and resolve it.

    Thanks for your understanding.
    Tuesday, June 28, 2016 7:11 AM
  • just tested your code but is prints only the name of the first ribbon

    code:

                foreach (Microsoft.Office.Tools.Ribbon.RibbonBase ribbon in Globals.Ribbons)
                {
                    System.Diagnostics.Debug.Print(ribbon.Name);
                }

    screenshot:



    • Edited by StefanM83 Tuesday, June 28, 2016 8:42 AM
    Tuesday, June 28, 2016 8:42 AM
  • >>>just tested your code but is prints only the name of the first ribbon

    According to your description, if you want to get Ribbon controls in Ribbon, I have made a sample, you could refer to below:

    Add Ribbon(Visual Designer) named "RibbonTempFile", then drag and drop Ribbon controls on it:


    foreach (Microsoft.Office.Tools.Ribbon.RibbonBase ribbon in Globals.Ribbons)
    {
        System.Diagnostics.Debug.Print(ribbon.Name);
        System.Diagnostics.Debug.Print(((RibbonTempFile)ribbon).tab1.Groups[0].Items[0].Id);
        RibbonButton button = (RibbonButton)((RibbonTempFile)ribbon).tab1.Groups[0].Items[0];
        System.Diagnostics.Debug.Print(button.Label);
    }


    Wednesday, June 29, 2016 1:55 AM
  • hi,

    at first I want to get the ribbon only!

    Please try to add two ribbons to your AddIn, RibbonTempFile1 and RibbonTempFile2.

    Now try the debug print the name of both by using foreach loop.

    foreach (Microsoft.Office.Tools.Ribbon.RibbonBase ribbon in Globals.Ribbons)
    {
        System.Diagnostics.Debug.Print(ribbon.Name);
    
    }

    the result should be 

    RibbonTempFile1
    RibbonTempFile2 

    Monday, July 4, 2016 1:23 PM
  • >>>Please try to add two ribbons to your AddIn, RibbonTempFile1 and RibbonTempFile2.

    According to your description, it seems that you want to add multiple Ribbon designs, if so, you are not able to add multiple Ribbon designs, but you could uses a condition to determine which custom Ribbon to display:
    protected override Microsoft.Office.Core.IRibbonExtensibility CreateRibbonExtensibilityObject()
    {
       if (myCondition == true)
       {
          return Globals.Factory.GetRibbonFactory().CreateRibbonManager(
                    new Microsoft.Office.Tools.Ribbon.IRibbonExtension[] { new RibbonTempFile1() });
       }
       else
       {
          return Globals.Factory.GetRibbonFactory().CreateRibbonManager(
                    new Microsoft.Office.Tools.Ribbon.IRibbonExtension[] { new RibbonTempFile2() });
       }
    }
    For more information, click here to refer about RibbonFactory.CreateRibbonManager Method (IRibbonExtension[])

    Tuesday, July 5, 2016 5:00 AM