问题描述
我正在使用多个RefEdit框在EXCEL 2016 VBA中开发一个用户窗体.当我使用MS开发的一种用户形式(例如,数据分析工具库中的Descriptive Statistics用户形式)时,该用户可以使用 + 或 + + 进行选择.
I am developing a userform in EXCEL 2016 VBA with a number of RefEdit boxs. When I use one of the MS developed userforms (like, for example, the Descriptive Statistics userform in the Data Analysis ToolPak), the user is able to use shortcut keys like + or ++ to make the selection.
目前,我的RefEdit框不支持此功能.是否可以在VBA中为典型的RefEdit框编码这些属性?如果是这样,有人可以提供示例代码吗?
At present, my RefEdit boxes do not support this function. Is it possible to code these attributes in VBA for a typical RefEdit box? If so, can someone please provide example code?
非常感谢,
丹
推荐答案
当我使用RefEdit
对象初始化任何表单时,我将运行以下代码. FixedRefEditKeys
只是全局Boolean
I run the following code when I initialize any form with RefEdit
Objects. FixedRefEditKeys
is just a Global Boolean
Public Sub FixRefEditKeys()
Dim sKey As String
'http://support.microsoft.com/kb/291110
If Not FixedRefEditKeys Then
sKey = "HKEY_CURRENT_USER\software\microsoft\office\" & Application.Version & "\Excel\Options\"
If Not RegKeyExists(sKey & "QFE_Richmond") Then RegKeySave sKey & "QFE_Richmond", 1, "REG_DWORD"
End If
End Sub
使用"my"(又称为Internet)Registry
模块中的以下内容:
Which uses the following from "my" (aka the Internet) Registry
Module:
'returns True if the registry key i_RegKey was found
'AND False if not
Function RegKeyExists(i_RegKey As String) As Boolean
Dim myWS As Object
On Error GoTo ErrorHandler
'access Windows scripting
Set myWS = CreateObject("WScript.Shell")
'try to read the registry key
myWS.RegRead i_RegKey
'key was found
RegKeyExists = True
Exit Function
ErrorHandler:
'key was not found
RegKeyExists = False
End Function
'sets the registry key i_RegKey to the
'value i_Value with type i_Type
'if i_Type is omitted, the value will be saved as string
'if i_RegKey wasn't found, a new registry key will be created
Sub RegKeySave(i_RegKey As String, _
i_Value As String, _
Optional i_Type As String = "REG_SZ")
Dim myWS As Object
'access Windows scripting
Set myWS = CreateObject("WScript.Shell")
'write registry key
myWS.RegWrite i_RegKey, i_Value, i_Type
End Sub
这篇关于在用户窗体中将键盘快捷方式与RefEdit框一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!