How to Detect the Current Keyboard Language with Word VBA
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.

- 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.
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.
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.
Press Alt + F11 on your keyboard or navigate to the Developer tab and click on 'Visual Basic'.
In the Project Explorer pane on the left, right-click on your document's project, select 'Insert', and then click 'Module'.
Type the following macro code into the module window: Sub DetectLanguage() MsgBox Application.Keyboard End Sub
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 Windows GetKeyboardLayoutName API (Word, Excel, PowerPoint)
A versatile approach that works across all Office applications by calling the native Windows API.
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. Install WPS Office: Download and install WPS Office, ensuring you have the version that includes VBA support.
- 2. Access the Developer Tab: Open your document in WPS Writer. Navigate to the Developer tab located on the top ribbon.
- 3. Open the Visual Basic Editor: Click the 'Visual Basic' button or press Alt + F11 to launch the integrated VBA editor.
- 4. Paste and Run Your Code: Insert a new module, paste your keyboard detection script, and press F5 to execute the macro perfectly.

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.




