重新聚焦在Excel Userform ComboBox上 [英] Re-Focusing on an Excel Userform ComboBox

查看:280
本文介绍了重新聚焦在Excel Userform ComboBox上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

用户正在将数据输入到ComboBox的编辑区域



ComboBox的更改事件用于运行以下代码:

  AppActivateMicrosoft Excel

'做一些东西

UserForm1.Show
UserForm1.ComboBox1.SetFocus

即使ComboBox现在再次具有焦点(根据Userform.ActiveControl),它没有指示这个事实的插入指针,并且用户必须重新选择ComboBox,然后才能继续输入数据



我想让它插入指针重新出现,用户可以继续直接输入数据,而不必重新选择ComboBox



添加以下代码

  SendKeys{TAB} + {TAB} {RIGHT}

是一个解决方案,但它是混乱的(它生成ComboBox事件,使用SendKeys最好避免, / p>

任何人都可以提出更好的解决方案?



Q。为什么黑羊吃的不如白羊?



A。因为没有那么多的

解决方案

事情是,userform本身可能没有焦点在工作表或其他



请尝试此代码:

  with UserForm1.ComboBox1 
.Visible = False
.Visible = True
.setfocus
end with


b $ b

或更一般地设置适当的焦点,调用此子:

  Sub Focus_ControlOfUserForm(ByRef Obj As Object) '从Userform,调用Focus_ControlOfUserForm(Me)
Dim ctl As Control
With Obj
设置ctl = .ActiveControl
如果TypeName(ctl)=MultiPage或TypeName )=Framethen
设置ctl = ctl.SelectedItem.ActiveControl.Name
结束如果

使用ctl
Dim Af As Boolean
With Application
Af = .ScreenUpdating
.ScreenUpdating = False
结束于
'.SetFocus
.Visible = False
.Visible = True
。 SetFocus
如果Af Then Application.ScreenUpdating = True
结束于
结束于
结束Sub

我也使用那种代码移动焦点到窗体,当我需要ControlTipText显示悬停。如果表单没有焦点,文本气泡将不会显示在鼠标悬停...


A User is Entering Data into the Edit Region of a ComboBox

The ComboBox's Change Event is used to run the following Code;

    AppActivate "Microsoft Excel"
        :
    'Do some stuff
        :
    UserForm1.Show
    UserForm1.ComboBox1.SetFocus

This works OK, BUT; even though the ComboBox now has the Focus again (according to the Userform.ActiveControl anyway), it has no Insertion Pointer to indicate this fact, and the User has to Re-Select the ComboBox before he can continue entering Data

I would like to have it so that the Insertion Pointer reappears and the User can continue Entering Data directly, without having to Re-Select the ComboBox

Adding the following line of Code

    SendKeys "{TAB}+{TAB}{RIGHT}"

is one solution, but it is messy (it generates ComboBox Events and using SendKeys is best avoided if possible anyway)

Can anyone suggest a better solution?

Q. Why do black sheep eat less than white sheep?

A. Because there aren't as many of them

解决方案

the thing is , the userform itself might not have focus over the worksheet or other userforms.

Try this code:

with UserForm1.ComboBox1
    .Visible = False
    .Visible = True
    .setfocus
end with

or more generally to set properly focus, call this sub:

Sub Focus_ControlOfUserForm(ByRef Obj As Object) 'from the Userform, call Focus_ControlOfUserForm(Me)
Dim ctl As Control
With Obj
    Set ctl = .ActiveControl
    If TypeName(ctl) = "MultiPage" Or TypeName(ctl) = "Frame" Then
        Set ctl = ctl.SelectedItem.ActiveControl.Name
    End If

    With ctl
        Dim Af As Boolean
        With Application
            Af = .ScreenUpdating
            .ScreenUpdating = False
        End With
        '.SetFocus
        .Visible = False
        .Visible = True
        .SetFocus 
        If Af Then Application.ScreenUpdating = True
    End With
End With
End Sub

I also use that kind of code to move focus to the Form when i need ControlTipText showing on hover. If the Form has no focus, the Text bubbles won't show on mouse hover...

这篇关于重新聚焦在Excel Userform ComboBox上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆