+ Reply to Thread
Results 1 to 7 of 7

password to restrict drilldown

  1. #1
    Forum Contributor
    Join Date
    03-11-2005
    Posts
    115

    password to restrict drilldown

    Hi I have been given this VBA which perfectly restricts the use of drill-down in a pivot-table, however I found that is only works on the worksheet that the code is in Is there anyway to sort it so it works on any pivot-table within the workbook file ?

    Sorry, but I am a new user on VBA !

    Sub RestrictPTuse()
    Dim p As PivotField
    With Sheets("table").PivotTables("PivotTable1")
    .EnableDrilldown = False
    .EnableWizard = False
    .PivotCache.EnableRefresh = True
    For Each p In .PivotFields
    p.DragToData = False
    p.DragToHide = False
    p.DragToColumn = False
    p.DragToRow = False
    p.DragToPage = False
    Next p
    End With
    End Sub

    Thanks for your help
    Amy xx

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hi Amy!

    I am giving you two versions of the macro. I wasn't sure it you wanted to run the macro once and apply this to all pivot tables in the workbook or be able to select the pivot table and worksheet when the macro is called.


    Run Once to Apply to All Pivot Tables:

    Sub RestrictPTuse()

    Dim p As PivotField
    Dim I As Integer
    Dim J As Integer

    For I = 1 To Excel.Worksheets.Count
    For J = 1 To Excel.PivotTables.Count
    With Sheets(I).PivotTables(J)
    .EnableDrilldown = False
    .EnableWizard = False
    .PivotCache.EnableRefresh = True
    For Each p In .PivotFields
    p.DragToData = False
    p.DragToHide = False
    p.DragToColumn = False
    p.DragToRow = False
    p.DragToPage = False
    Next p
    End With
    Next J
    Next I

    End Sub



    Ask for Worksheet and Pivot Table Name:

    Sub RestrictPTuse()

    Dim p As PivotField
    Dim WksName As String
    Dim PvtName As String

    WksName = InputBox("Enter the Name of the Worksheet in the Box Below.")
    If WksName = "" Then Exit Sub

    PvtName = InputBox("Enter the Name of the Pivot Table in the Box Below.)
    If PvtName = "" Then Exit Sub

    With Sheets(WksName).PivotTables(PvtName)
    .EnableDrilldown = False
    .EnableWizard = False
    .PivotCache.EnableRefresh = True
    For Each p In .PivotFields
    p.DragToData = False
    p.DragToHide = False
    p.DragToColumn = False
    p.DragToRow = False
    p.DragToPage = False
    Next p
    End With

    End Sub


    The choice is yours!
    Leith Ross

  3. #3
    Forum Contributor
    Join Date
    03-11-2005
    Posts
    115
    Hi Leith, thank you for the emails, I have a problem however:

    When I run the code, I get a compile error "method or data member not found" ?
    Can you help please ?

    Amy xx

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hi Amy,

    Which macro did you run? Can you tell me which line in the code is causing the problem?

    Thanks,
    Leith Ross

  5. #5
    Forum Contributor
    Join Date
    03-11-2005
    Posts
    115
    Hi Leith

    Sub RestrictPTuse()

    Dim p As PivotField
    Dim I As Integer
    Dim J As Integer

    For I = 1 To Excel.Worksheets.Count
    For J = 1 To Excel.PivotTables.Count -- this line is causing the error.
    With Sheets(I).PivotTables(J)
    .EnableDrilldown = False
    .EnableWizard = False
    .PivotCache.EnableRefresh = True
    For Each p In .PivotFields
    p.DragToData = False
    p.DragToHide = False
    p.DragToColumn = False
    p.DragToRow = False
    p.DragToPage = False
    Next p
    End With
    Next J
    Next I

    End Sub

    Line "For J = 1 To Excel.PivotTables.Count" is causing the error

    Amy xx

  6. #6
    Forum Contributor
    Join Date
    03-11-2005
    Posts
    115
    Hi, I am using Visual Basic v 6.3 if that helps ?!

    I have tried changing the line to "For J = 1 To Excel.xlPivotTable.Count" of similar but I cant get it to work !

    Amy xx

  7. #7
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hi Amy,

    My mistake. I assumed there was a Pivot Table on each Worksheet. The "J" loop needs to placed inside an IF statement that tests if the Worksheet has any Pivot Tables. Here is the correction.

    Corrected Code:

    Sub RestrictPTuse()

    Dim p As PivotField
    Dim I As Integer
    Dim J As Integer

    For I = 1 To Excel.Worksheets.Count

    If Worksheets(I).PivotTables.Count <> 0 Then

    For J = 1 To Excel.PivotTables.Count
    With Sheets(I).PivotTables(J)
    .EnableDrilldown = False
    .EnableWizard = False
    .PivotCache.EnableRefresh = True
    For Each p In .PivotFields
    p.DragToData = False
    p.DragToHide = False
    p.DragToColumn = False
    p.DragToRow = False
    p.DragToPage = False
    Next p
    End With
    Next J

    End If

    Next I

    End Sub


    Sincerely,
    Leith Ross

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1