Microsoft KB Archive/246501
Article ID: 246501
Article Last Modified on 5/13/2007
- Microsoft Office Excel 2007
- Microsoft Office Excel 2003
- Microsoft Excel 2002 Standard Edition
- Microsoft Excel 2000 Standard Edition
- Microsoft Visual C++ 6.0 Professional Edition
- Microsoft Visual C++ 5.0 Professional Edition
- Microsoft Foundation Class Library 4.2
This article was previously published under Q246501
When setting the currency format for an Excel range from an out-of-process Automation client, it is necessary to specify an explicit Locale ID (LCID) if the function should operate using a locale different from the operating system.
If you Automate Excel from a remote client using Visual C++, you need to be sure that the LCID for the call is specifically known by Excel.
Most Excel functions take an LCID parameter when early binding. If late binding, the LCID passed to IDispatch::Invoke is used as the LCID parameter for the function being called. If you do not explicitly set the LCID to a valid value, Excel assumes the system default.
For example, if you are developing on a system with an English (United States) operating system and you want the Excel currency setting to show DM for German currency, but you ignore the Locale ID, then Excel formats the result with the dollar sign ($) instead of the German currency (DM). Excel does this even if German has been set under the Regional Settings in Control Panel. This is because an LCID of zero is assumed to be the default locale for the system and not a user. Since the system is English (United States), in this example, the currency is displayed in U.S. Dollars.
This can be a problem if the Automation program uses the MFC COleDispatchDriver wrapper classes, because they do not natively support passing a custom LCID. Instead, MFC always passes LOCAL_SYSTEM_DEFAULT as the LCID in its InvokeHelper function. If you need to invoke an Excel Automation function with an explicit LCID, you cannot use InvokeHelper function in MFC, and should instead call IDispatch::Invoke directly.
You will find a table of the numeric values for various locale IDs in the Platform SDK on MSDN.
Search for "Language Identifier" (use the quotes), then scroll to select the topic Language Identifiers - International Features (without the quotes.) You can also find information about it in the WINNT.H, the OLENLS.H and/or the WINNLS.H files.
Keywords: kbautomation kbinfo KB246501