3

是否可以拦截对数据透视表的双击,阻止其显示基础数据,以便您可以提供希望查看者看到的结构化屏幕?

4

3 回答 3

1

根据 Siddharth Rout 的回答,这完全是从偷来的,但会更灵活,因为它会查看工作表上的所有数据透视表,如果你双击其中任何一个,它就会取消:

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    Dim rng As Range
    Dim wks As Worksheet
    Dim pt As PivotTable

    Set wks = Target.Worksheet
    For Each pt In wks.PivotTables()
        Set rng = Range(pt.TableRange1.Address)
        If Not Intersect(Target, rng) Is Nothing Then
            Cancel = True
        End If
    Next
End Sub
于 2014-01-28T00:35:34.140 回答
1

尝试这个。

逻辑

  1. 确定您的支点范围
  2. Worksheet_BeforeDoubleClick事件中检查用户是否点击了 Pivot
  3. 取消双击

代码:此代码进入具有枢轴的工作表代码区域(见截图)

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    Dim rng As Range

    '~~> This is your pivot table range. Change as applicable
    Set rng = Range("A1:D10")

    '~~> Check if the double click happend in the Pivot
    If Not Intersect(Target, rng) Is Nothing Then
        '~~> Cancel Double click
        Cancel = True
    End If
End Sub

屏幕截图

在此处输入图像描述

于 2012-09-21T09:48:59.467 回答
1

您可以尝试执行类似于以下代码的操作。这将创建一个范围、工作表和数据透视表:

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    Dim rng As Range
    Dim wks As Worksheet
    Dim pt As PivotTable

    Set wks = Target.Worksheet
    For Each pt In wks.PivotTables()
        Set rng = Range(pt.TableRange1.Address)
        If Not Intersect(Target, rng) Is Nothing Then


            Cancel = True
        End If
    Next
End Sub
于 2015-07-09T11:44:07.373 回答