Changing the keyboard language with VBA

mmn1000

Board Regular
Joined
Mar 17, 2020
Messages
76
Office Version
  1. 2019
  2. 2013
Platform
  1. Windows
Hi;
Changing the keyboard language from one language to another by option button and in the user form.
I am planning to create two option buttons in the user form for each of the Farsi and English languages.
That is, if Farsi is selected, the keyboard language will be Farsi and vice versa.
Thanks
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
You can do it with the PowerShell Set-WinUserLanguageList command, run by VBA. Follow the PowerShell steps at How to Set Default Keyboard Layout in Windows 10 to determine the language tags for all your keyboard languages.

Edit the following 2 procedures as appropriate for the default language required. All your language tags should be specified after the -LanguageList parameter and the first one becomes the default keyboard language. Unable to test this because I only have 1 keyboard language.

VBA Code:
Public Sub Set_Farsi()
    Shell "PowerShell Set-WinUserLanguageList -LanguageList farsi, en-GB -Force"
End Sub

Public Sub Set_English()
    Shell "PowerShell Set-WinUserLanguageList -LanguageList en-GB, farsi -Force"
End Sub
You can then call the above procedures as appropriate from your user form code.
 
Upvote 0
کسی راه حلی نداره
You can do it with the PowerShell Set-WinUserLanguageList command, run by VBA. Follow the PowerShell steps at How to Set Default Keyboard Layout in Windows 10 to determine the language tags for all your keyboard languages.

Edit the following 2 procedures as appropriate for the default language required. All your language tags should be specified after the -LanguageList parameter and the first one becomes the default keyboard language. Unable to test this because I only have 1 keyboard language.

VBA Code:
Public Sub Set_Farsi()
    Shell "PowerShell Set-WinUserLanguageList -LanguageList farsi, en-GB -Force"
End Sub

Public Sub Set_English()
    Shell "PowerShell Set-WinUserLanguageList -LanguageList en-GB, farsi -Force"
End Sub
You can then call the above procedures as appropriate from your user form code.
Thanks

I want to change the default language of the Text Box by selecting any of the Option Buttons
 
Upvote 0
Do the 2 procedures work or not?

Your userform module should be something like this:
VBA Code:
Private Sub UserForm_Initialize()
    'Set initial language
    OptionButton1_Click
End Sub

Private Sub OptionButton1_Click()
    Set_English
    Me.TextBox1 = "English"
End Sub

Private Sub OptionButton2_Click()
    Set_Farsi
    Me.TextBox1 = "Farsi"
End Sub

Public Sub Set_English()
    Shell "PowerShell Set-WinUserLanguageList -LanguageList en-GB, farsi -Force"
End Sub

Public Sub Set_Farsi()
    Shell "PowerShell Set-WinUserLanguageList -LanguageList farsi, en-GB -Force"
End Sub
 
Upvote 0
Do the 2 procedures work or not?

Your userform module should be something like this:
VBA Code:
Private Sub UserForm_Initialize()
    'Set initial language
    OptionButton1_Click
End Sub

Private Sub OptionButton1_Click()
    Set_English
    Me.TextBox1 = "English"
End Sub

Private Sub OptionButton2_Click()
    Set_Farsi
    Me.TextBox1 = "Farsi"
End Sub

Public Sub Set_English()
    Shell "PowerShell Set-WinUserLanguageList -LanguageList en-GB, farsi -Force"
End Sub

Public Sub Set_Farsi()
    Shell "PowerShell Set-WinUserLanguageList -LanguageList farsi, en-GB -Force"
End Sub
Hi

In your code, it types English and Farsi words in the text box
See the attached file that in the first text box only Farsi is typed, in the second text box only English and in the third text box only numbers are typed by default.


In the fourth text box, I want it to work like the first and second text boxes by selecting the desired option button
 

Attachments

  • d.png
    d.png
    11.4 KB · Views: 12
Upvote 0
In your code, it types English and Farsi words in the text box

That was just to prove that English/Farsi has been selected. For normal use you wouldn't have Me.TextBox1 = "English" or Me.TextBox1 = "Farsi"

Do the 2 procedures change the input language when they are run as macros, separate from the userform? Put the code in a normal module and run them to find out. If they don't then they won't in the userform.

In the fourth text box, I want it to work like the first and second text boxes by selecting the desired option button

That's exactly what my Private Sub OptionButton1_Click() and Private Sub OptionButton2_Click() do, but they won't change the language if the PowerShell commands don't work.
 
Upvote 0
Solution

Forum statistics

Threads
1,215,054
Messages
6,122,895
Members
449,097
Latest member
dbomb1414

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top