Nickolay
Nickolay

Reputation: 32063

Getting language for non-unicode programs in VBA

How do I get the value of "Language for Non-Unicode Programs" in Control Panel Regional Settings programmatically using VBA?

My VBA code contains Cyrillic constants, which get garbled if the Language for non-unicode programs is not Russian, so I'd like to advise the user to change the setting before trying to use the app.

See Getting Language for Non-Unicode Programs for a similar question for C#

Upvotes: 1

Views: 1214

Answers (1)

Nickolay
Nickolay

Reputation: 32063

Public Declare Function GetACP Lib "kernel32" () As Long

Sub CheckANSICodePage()
    If GetACP() <> 1252 Then
        MsgBox "This application requires 'Language for non-Unicode programs' to be set to English " & _
               "in the Control Panel and will not function properly otherwise." & vbCrLf & _
                vbCrLf & _
                "Press OK to exit.", vbCritical + vbOKOnly, "MyApp"
        ActiveWorkbook.Close SaveChanges:=False
    End If
End Sub

From NLS Terminology page in Internationalization for Windows Applications:

An ANSI application should check the language for non-Unicode programs setting during installation. It uses GetACP or GetOEMCP to retrieve the value. No function is supported to set the language for non-Unicode programs.

The GetACP function returns the "ANSI code page" (e.g. 1252 for english), while GetOEMCP returns the "OEM code page" (the code page used in the console, 437 for english).

Code Pages has more information about code pages in Windows.

Upvotes: 1

Related Questions