双击时避免在表单中进行选择 [英] Avoid selection in a form when double-click

查看:95
本文介绍了双击时避免在表单中进行选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

excel-2007 我有一个宏,当双击单元格时,窗体将打开。

In excel-2007 I have a macro that when double clicking a cell, a form will open.

当相关单元格位于窗体出现的范围内时,会出现不需要的选择以形式进行。

When the relevant cell is located within the range in which the form will appear, an undesired selection is carried out in the form.

如何避免此选择?

>从hammejdp对barrowc的回答的建议编辑:

我使用这个(即BeforeDoubleClick事件)已经但不能修复问题

I use this (i.e. BeforeDoubleClick event) already but not fix the problem

Private Sub Workbook_SheetBeforeDoubleClick(ByVal sh As Object, ByVal target As Range, cancel As Boolean)

Call s_Click_DoubleClick(sh, target, cancel)

End Sub

Private Sub Workbook_SheetBeforeRightClick(ByVal sh As Object, ByVal target As Range, cancel As Boolean)

Call s_Click_DoubleClick(sh, target, cancel)

End Sub

Private Sub s_Click_DoubleClick(sh, target, cancel)

Application.ScreenUpdating = False

If sh.Name <> "Legende" Then
    cancel = True
    ' Maak gebruik van een range
    vRowCount = target.Rows.Count
    vColumnCount = target.Columns.Count
    f_Input.TextBox1.Value = vColumnCount


推荐答案

设置取消= True不会工作。这是一些解决问题的代码。这不漂亮,但它的作品。首先,当用户表单初始化时,禁用ListBox:

Setting Cancel = True will not work. Here is some code that will resolve the issue. It's not pretty, but it works. First, disable the ListBox when the user form initializes:

Private Sub UserForm_Initialize()
    Me.listMyList.Enabled = False
End Sub

这将阻止BeforeDoubleClick事件的第二次点击被解释为在用户表单中的列表框中的选择(或者更确切地说,它将阻止第二次点击的能力被解释为因为控件不被启用)。接下来,在用户窗体的MouseDown事件上启用ListBox:

This will prevent the second click from the BeforeDoubleClick event from being interpreted as a selection in the List box on the user form (or rather, it will block the ability for the second click to be interpreted as such because the control is not Enabled). Next, enable the ListBox on the user form's MouseDown event:

Private Sub UserForm_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
    Me.listMyList.Enabled = True
End Sub

它不漂亮,但它的工作。

It's not pretty, but it works.

这篇关于双击时避免在表单中进行选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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