检测设置Excel的语言并将其显示在文件的单元格中 [英] Detect the language in which Excel is setup and show it in a cell of the file

查看:46
本文介绍了检测设置Excel的语言并将其显示在文件的单元格中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在设计一组相互之间相关的Excel文件.目的是互相引用文档的宏可以在任何给定的计算机/路径中工作.因此,我使用了一组相对路径,这些路径可以使宏正常工作.

我使用了以下功能:

  = + CELDA("nombrearchivo"; $ A $ 1) 

"nombredearchivo" 的英文意思是文件名" .

这里的问题是,仅当使用西班牙语设置计算机时此功能才起作用,但是当文件传输到英语设置的计算机时,它将功能CELDA转换为CELL,而不是"nombrearchivo".

为解决此问题,我考虑过尝试在单元格中显示设置Excel的语言,然后编写一种if函数,该函数使用三种主要语言显示nombrearchivo,文件名或任何其他语言的相同语言.

是否可以在单元格中显示设置excel的语言?

目标是宏ccan可以在任何给定的计算机和路径上工作.

解决方案

此答案完全从此来源中提取:

要获取您需要输入的十进制数字,可以使用如下代码:

 函数GetLanguage()作为字符串GetLanguage = GetLanguageName(Application.LanguageSettings.LanguageID(msoLanguageIDUI))结束功能 

因此,在单元格中键入 GetLanguage()将返回用户的语言.

希望您可以使其适应您的需求.

I'm designing a set of related excel file which are related between them. The objective is that the macros which refere to each other document, can work in any given computer/path. For this reason I have used a set of relative path which lets the macros work well.

I have used the follwoing functions:

=+CELDA("nombrearchivo";$A$1)

"nombredearchivo" means "filename" in english.

The problem here is that this function only works when the computer is setup in Spanish, but when the files are transferred to a English set up computer, it translates de function CELDA to CELL, but not the "nombrearchivo".

To solve it I have thought about trying to show in cell the language in which Excel is setup and then write an if function with three main languages which would display the nombrearchivo, filename or the same in any other language.

Is it possible to show in a cell the language in which excel is setup??

The objective is that the macros ccan work at any given computer and path.

解决方案

This answer is totally extracted from this source:

https://www.mrexcel.com/forum/excel-questions/617870-language-code-french-spanish-spanish.html

So all credits go to original author Leith Ross:

' Written: March 01, 2012
' Author:  Leith Ross
' Summary: Converts a Language Code Identifier (LCID) into the language name.

Private Declare Function GetLocaleInfoA _
    Lib "kernel32.dll" _
        (ByVal Locale As Long, _
         ByVal LCType As Long, _
         ByVal lpLCData As String, _
         ByVal cch As Long) _
    As Long

Function GetLanguageName(ByVal LCID As Long) As String

    Const LOCALE_SENGLANGUAGE As Long = &H1001
    Const LOCALE_SENGCOUNTRY As Long = &H1002

    Dim Buffer As String
    Dim BuffSize As Long
    Dim RetVal As Long

        BuffSize = GetLocaleInfoA(LCID, LOCALE_SENGLANGUAGE, 0, 0)
        Buffer = String(BuffSize, Chr(0))

        RetVal = GetLocaleInfoA(LCID, LOCALE_SENGLANGUAGE, Buffer, BuffSize)

        If RetVal > 0 Then GetLanguageName = Left(Buffer, BuffSize - 1)

End Function

To test it, just type in a cell =GetLanguageName(1034) (decimal value) but it works also with Hex value, like =GetLanguageName("&H40A")

I got this in my Excel:

And to get the decimal number you need to type, you can use something like this:

Function GetLanguage() As String
GetLanguage = GetLanguageName(Application.LanguageSettings.LanguageID(msoLanguageIDUI))
End Function

So typing in a cell GetLanguage() will return the user's language.

Hope you can adapt this to your needs.

这篇关于检测设置Excel的语言并将其显示在文件的单元格中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆