logo
search
VBA & Macro Problems

How to Detect the Current Keyboard Language with Word VBA

Adam DavisAdam Davis Sep 25, 2026 869 views

Question details

Identify whether the active keyboard layout is English, Arabic, or another language and display the result using a message box in a VBA macro.

How to Detect the Current Keyboard Language with Word VBA
Product
Word
Device & OS
Windows
Scenario
Writing a VBA macro that needs to determine the user's active keyboard language to execute specific formatting or logic.
Observed behavior
Retrieving the system's active keyboard language identifier successfully and mapping it to a readable name within Word, Excel, or PowerPoint VBA environments.
Before you start

Ensure that the Developer tab is enabled in your Office application's ribbon and that you have permitted macro execution in your Trust Center settings.

Solution 1Recommended

Use the Application.Keyboard Property (Word Only)

This is the most straightforward method, utilizing Word's built-in Application.Keyboard property to display the language identifier.

This method relies on a native Word property and does not require complex API calls. However, it is exclusively available in the Word object model and will trigger an error if used in Excel or PowerPoint.

1
Open the Visual Basic Editor

Press Alt + F11 on your keyboard or navigate to the Developer tab and click on 'Visual Basic'.

2
Insert a New Module

In the Project Explorer pane on the left, right-click on your document's project, select 'Insert', and then click 'Module'.

3
Input the VBA Code

Type the following macro code into the module window: Sub DetectLanguage() MsgBox Application.Keyboard End Sub

4
Run the Macro

Press F5 or click the Run button. A message box will display a specific numeric identifier (e.g., 1033 for English, 1025 for Arabic) representing the current keyboard language.

Use the Application.Keyboard Property (Word Only)
Mapping Language Codes: You can enhance this code by adding an If-Else or Select Case statement to convert the numeric output (LCID) into readable text like 'English' or 'Arabic'.
Advanced VBA Compatibility

Run VBA Macros Seamlessly in WPS Office

WPS Office provides robust and highly compatible support for VBA macros, allowing you to run your keyboard detection scripts and automate tasks across documents seamlessly.

  1. 1. Install WPS Office: Download and install WPS Office, ensuring you have the version that includes VBA support.
  2. 2. Access the Developer Tab: Open your document in WPS Writer. Navigate to the Developer tab located on the top ribbon.
  3. 3. Open the Visual Basic Editor: Click the 'Visual Basic' button or press Alt + F11 to launch the integrated VBA editor.
  4. 4. Paste and Run Your Code: Insert a new module, paste your keyboard detection script, and press F5 to execute the macro perfectly.
Full compatibility with Microsoft Office VBA scripts and macrosSeamless support for standard DOCM, XLSM, and PPTM file formatsLightweight architecture for faster macro execution and document loadingFamiliar Visual Basic Editor interface with zero learning curve
microsoft office alternative - wps office

Frequently Asked Questions

Why does Application.Keyboard give an error in Excel or PowerPoint?

The Application.Keyboard property is exclusive to the Word object model. To achieve the same functionality in Excel or PowerPoint, you must use the Windows API function GetKeyboardLayoutName.

How do I make my VBA macro available in all Office applications?

Code placed in one application's VBA project is not automatically shared across the Office suite. You must manually copy the VBA module and paste it into the Visual Basic Editor of each specific workbook, presentation, or document where you intend to use the macro.

What do the numbers returned by Application.Keyboard mean?

The property returns the Language Code Identifier (LCID) corresponding to the active keyboard layout. For instance, it typically returns 1033 for US English and 1025 for Arabic. You can write logic in your macro to translate these numeric identifiers into user-friendly language names.