How to: Localize Excel Solutions
Localization consists primarily of translating the user interface of your application. Instead of hard coding strings into your application, you should store the strings in a separate file. You can store strings for Microsoft Office Excel 2003 user interface elements in the project's default assembly resource file. The file is named MyResources.resx in Visual Basic projects, and Resources.resx in C# projects. Copies of the resource file can then be translated into multiple languages.
The dialog boxes and menu commands you see might differ from those described in Help depending on your active settings or edition. To change your settings, choose Import and Export Settings on the Tools menu. For more information, see.
Storing Text in a Resource File
To add text to a resource file
Open the Excel project that you want to localize.
On the Project menu, select <Projectname> Properties.
The Project Designer opens.
Click Resources in the Project Designer to open the Resources pane.
Select Strings in the Categories combo box.
Add a unique identifier to the Name column and the text to be localized in the Value column for each string you want to localize. For example:
create unscheduled order
You can use the Comment column to provide notes or instructions to the translator.
Retrieving Text from a Resource File
After you have added each string to the resource file, the strings can be loaded at runtime.
To add a value to a cell using a Resource file.
Startupevent handler of
Sheet1, add a control to cell A1.
Assign a value from the resource file.
Localizing the Resource File
To localize a resource file
Copy the resource file and name it with the culture code of the target language. For example, to create a file that will be localized into Japanese, copy the Resources.resx file and name it Resources.ja.resx.
Have the resource file translated into the languages you want to support. For example, have the strings in Resources.ja.resx translated into Japanese.
Add the translated resource files to your project so that the project system can compile the resource files into satellite assemblies.
Loading Resources Based on Office User Interface Language
The Microsoft .NET Framework loads resources based on the Microsoft Windows user interface language. Office-based solutions, however, are typically written to load resources based on the Office user interface (UI) language. The first example below demonstrates how to load resources that match the Office UI language, regardless of which version of Office is installed. The second example shows how to override both the Office UI language and the default Microsoft .NET Framework behavior.
To load resources based on Office (multiple language versions of Office)
Add the following code to the
Startupevent handler for the workbook and each of the worksheets.
If you do not have multiple language versions of Office, you can force resources to load by assigning the matching culture ID to theproperty of the object (or that of the current thread). This can be useful for debugging purposes, or as part of custom code that allows users to select which resources to load.
To load resources based on Office (using the Culture ID)
Add the following code to the
Startupevent handler for the workbook and each of the worksheets. This example passes the culture ID for German (Germany). For a list of culture IDs, see CultureInfo.
Localizing Custom Controls
You can add custom controls to the actions pane in Microsoft Visual Studio 2005 Tools for the Microsoft Office System solutions. You can enable localization of a user control or an actions pane control in the same way you would localize a Windows form. For more information see,.
To enable localization of a custom control
From the View menu, select Properties Window.
Select the user control or actions pane control in the designer and change the Localizable property to true.