消息框中的翻译[关闭]

问题描述 投票:0回答:1

消息框中的 Excel 翻译。 我可以在自定义菜单中分配快捷方式或添加 VBA,一旦单击任何选择(只有一个单元格而不是多个单元格),翻译就会填充在消息框中。 我可以点击“关闭”或“确定”

excel vba translate
1个回答
0
投票

Validation.InputMessage
属性(和
Validation.InputTitle
属性
)是固定字符串,不接受公式。

但是,如果您有验证单元格和翻译选项的列表或数组,则可以在打开工作簿(即

Workbook_Open()
事件)时使用 VBA 进行迭代,以将
Validation.InputMessage
更改为当前用户的语言。

(您可以使用

<Range>.SpecialCells(xlCellTypeAllValidation)
获取某个范围内包含 Validation 的单元格,例如
ActiveSheet.UsedRange.SpecialCells(xlCellTypeAllValidation)
获取 ActiveSheet 中包含 Validation 的所有单元格)

Private Sub Workbook_Open()
    Dim ws As Worksheet, valid As Range, ar As Range, rng As Range
    
    Dim Lang As Long
    Lang = Application.LanguageSettings.LanguageID(msoLanguageIDUI) 'Get UI Language
    'https://learn.microsoft.com/en-us/office/2016/language/language-identifiers-optionstate-id-values
    
    For Each ws In ThisWorkbook.Worksheets
        On Error Resume Next
        Set valid = ws.UsedRange.SpecialCells(xlCellTypeAllValidation)
        On Error GoTo 0
        If Not (valid Is Nothing) Then
            For Each ar In valid.Areas
                For Each rng In ar.Cells
                    If rng.Validation.ShowInput Then
                        Select Case rng.Validation.InputTitle
                            Case "Err404":
                                Select Case Lang
                                    Case 1033 'English
                                        rng.Validation.InputMessage = "Data Not Found"
                                    Case 1031 'German
                                        rng.Validation.InputMessage = "Daten Nicht Gefunden"
                                    Case 3082 'Spanish
                                        rng.Validation.InputMessage = "Datos no encontrados"
                                End Select
                            Case "Err418":
                                Select Case Lang
                                    Case 1033 'English
                                        rng.Validation.InputMessage = "I'm a teapot!"
                                    Case 1031 'German
                                        rng.Validation.InputMessage = "Ich bin eine Teekanne!"
                                    Case 3082 'Spanish
                                        rng.Validation.InputMessage = "Soy una tetera!"
                                End Select
                        End Select
                    End If
            Next rng, ar
        End If
    Next ws
End Sub
© www.soinside.com 2019 - 2024. All rights reserved.