英文:
How to change the language of Windows by a macro in excel?
问题
我创建了一个表单。它的名字是FF,该表单通过一个简单的模块显示:
Sub SH()
FF.Show = True
End Sub
这个表单包含一些按钮,我使用以下代码为这些按钮设置了快捷键:
CommandButton1.Accelerator = "H"
CommandButton2.Accelerator = "A"
Command...
如果Windows的语言是英文并且我显示表单,快捷键可以正常工作,但如果不是英文并且显示表单,那么快捷键将无法工作(即使我按下"Alt+左Shift")。
因此,我必须在显示表单之前按下"Alt+左Shift"。但这可能会被遗忘... 我想我应该在"FF.Show = True"之前放一些代码来将Windows的语言更改为英文。是否有任何代码可以解决我的问题?
感谢您的帮助。
英文:
I have created a form. It's name is FF and the form
is showed with a simple module:
sub SH()
FF.show=true
End sub
This form contains some buttons and I have put shortcuts for these buttons with
the following codes:
CommandButton1.Accelerator = "H"
CommandButton2.Accelerator = "A"
Command...
If the language of Windows is English and I show the form,
the shortcuts work correctly, but if it is not English
and the form is shown, then the shortcuts does not work (even if I press the "Alt+leftShift").
So I have to press "Alt+leftShift" before I show the form.
But this can be forgettable and... .I think I shoud put some codes before "FF.show=true"
to change the language of windows to English. Is there any code that solve my problem?
Thank you for your help
答案1
得分: 1
Two languages are installed on my computer. I am using two Functions to change the keyboard through VB
Option Explicit
#If VBA7 Then
Private Declare PtrSafe Function ActivateKeyboardLayout Lib "user32" (ByVal HKL As LongPtr, ByVal flag As Long) As LongPtr
#Else
Private Declare Function ActivateKeyboardLayout Lib "user32.dll" (ByVal HKL As Long, flag As Long) As Long
#End If
Public Function ELLHNIKA() As Integer
If ActivateKeyboardLayout(1032, 0) = 0 Then
MsgBox ("Unable to select Greek keyboard")
ELLHNIKA = -1
Else
ELLHNIKA = 0
End If
End Function
Public Function ENGLISH() As Integer
If ActivateKeyboardLayout(1033, 0) = 0 Then
MsgBox ("Unable to select English keyboard")
ENGLISH = -1
Else
ENGLISH = 0
End If
End Function
If you want to switch between the installed languages then use this version:
Public Sub NextLang()
Call ActivateKeyboardLayout(1, 0)
End Sub
英文:
Two languages are installed on my computer. I am using two Functions to change the keyboard through VB
Option Explicit
#If VBA7 Then
Private Declare PtrSafe Function ActivateKeyboardLayout Lib "user32" (ByVal HKL As LongPtr, ByVal flag As Long) As LongPtr
#Else
Private Declare Function ActivateKeyboardLayout Lib "user32.dll" (ByVal HKL As Long, flag As Long) As Long
#End If
Public Function ELLHNIKA() As Integer
If ActivateKeyboardLayout(1032, 0) = 0 Then
MsgBox ("Unable to select Greek keyboard")
ELLHNIKA = -1
Else
ELLHNIKA = 0
End If
End Function
Public Function ENGLISH() As Integer
If ActivateKeyboardLayout(1033, 0) = 0 Then
MsgBox ("Unable to select English keyboard")
ENGLISH = -1
Else
ENGLISH = 0
End If
End Function
If you want to switch between the installed languages then use this version:
Public Sub NextLang()
Call ActivateKeyboardLayout(1, 0)
End Sub
https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-activatekeyboardlayout
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论