控制行标题的双击事件

所以我很熟悉引用工作表事件(如双击)的工作表范围。 在这种情况下,我正在寻找引用何时行标题被双击,而不是一个单元格。 它仍然是具体的工作表,但我迄今没有成功。

我有多个范围,双击不同的事件,所以我使用代码类似于下面的例子:

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean) Dim rWatchRange As Range Dim sWatchRange As Range Set rWatchRange = Range("A5:A1000") 'I somehow need it to recognize if the row header is 'double clicked between row 5 and 1000 to fire off the second sub Set sWatchRange = Range("5:1000") If Not Application.Intersect(Target, rWatchRange) Is Nothing Then Run "aFormattingSub" End If If Not Application.Intersect(Target, sWatchRange) Is Nothing Then Run "aSubToInsertNewLineAndGroupWithRowAbove" End If End Sub 

我不知道是否有工作表参考,应用程序参考或Excel中的设置,我知道这可以做到这一点。

双击标题时,DoubleClick事件不会触发。 我不认为有这样一个微不足道的方法 – 你必须与提供的事件一起生活。

我认为还有足够的空间来实现更多的function。
为了给你更多的想法,你可以做双击或按住Ctrl键不同的事情。

一个例子,按住ctrl的同时点击右键,只有当选中整行时:

 Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean) If (GetKeyState(KeyCodeConstants.vbKeyControl) And &H8000) And _ Selection.Address = Selection.EntireRow.Address Then Cancel = True ' ... code End If End Sub 

And &H8000只需要对当前的现在作出反应,而忽略以前的按键)

在模块中导入API函数:

 Public Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer