Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,836
Default If Pivot Table Exists, Delete on Close

I am wondering if there is some simple code that I can run that will
automatically delete all Pivot tables in a Workbook, upon close of the
Workbook, or delete all sheets that contain Pivot Tables, upon close of the
Workbook. I have an Excel file on our firms LAN, which contains a lit of
useful data for several VPs, who go into the file to check certain items, and
make a few updates. I would like to give them a way to create Pivot Tables
on the fly (I already have the code for this) but I dont want them to be
able to save the Pivot Tables because I surmise it will quickly bloat to un
unmanageable size and the performance (over the LAN) will slow considerably.
Again, I just want to save a few changes that some of the VPs will make, in
their forecasting, and then automatically delete any and all Pivot Tables.

I suspect it will look something like this:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
€˜If Pivot Table 1 Then
€˜Delete Pivot Table
€˜End if
End Sub


Thanks in advance!!
Ryan---

--
RyGuy
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,979
Default If Pivot Table Exists, Delete on Close

Dim pt As PivotTable
Dim ws As Worksheet

For Each ws In ActiveWorkbook.Worksheets
For Each pt In ws.PivotTables
pt.TableRange2.Clear
Next pt
Next ws


ryguy7272 wrote:
I am wondering if there is some simple code that I can run that will
automatically delete all Pivot tables in a Workbook, upon close of the
Workbook, or delete all sheets that contain Pivot Tables, upon close of the
Workbook. I have an Excel file on our firms LAN, which contains a lit of
useful data for several VPs, who go into the file to check certain items, and
make a few updates. I would like to give them a way to create Pivot Tables
on the fly (I already have the code for this) but I dont want them to be
able to save the Pivot Tables because I surmise it will quickly bloat to un
unmanageable size and the performance (over the LAN) will slow considerably.
Again, I just want to save a few changes that some of the VPs will make, in
their forecasting, and then automatically delete any and all Pivot Tables.

I suspect it will look something like this:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
€˜If Pivot Table 1 Then
€˜Delete Pivot Table
€˜End if
End Sub


Thanks in advance!!
Ryan---



--
Debra Dalgleish
Contextures
www.contextures.com/tiptech.html
Blog: http://blog.contextures.com

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,836
Default If Pivot Table Exists, Delete on Close

This seems to have worked very nicely. I have never used 'TableRange2'
before. What is this??? Please respond!!! I googled it and didn't find a
whole lot of information on 'TableRange2'...

Thanks for the help!
Ryan---

--
RyGuy


"Debra Dalgleish" wrote:

Dim pt As PivotTable
Dim ws As Worksheet

For Each ws In ActiveWorkbook.Worksheets
For Each pt In ws.PivotTables
pt.TableRange2.Clear
Next pt
Next ws


ryguy7272 wrote:
I am wondering if there is some simple code that I can run that will
automatically delete all Pivot tables in a Workbook, upon close of the
Workbook, or delete all sheets that contain Pivot Tables, upon close of the
Workbook. I have an Excel file on our firms LAN, which contains a lit of
useful data for several VPs, who go into the file to check certain items, and
make a few updates. I would like to give them a way to create Pivot Tables
on the fly (I already have the code for this) but I dont want them to be
able to save the Pivot Tables because I surmise it will quickly bloat to un
unmanageable size and the performance (over the LAN) will slow considerably.
Again, I just want to save a few changes that some of the VPs will make, in
their forecasting, and then automatically delete any and all Pivot Tables.

I suspect it will look something like this:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
€˜If Pivot Table 1 Then
€˜Delete Pivot Table
€˜End if
End Sub


Thanks in advance!!
Ryan---



--
Debra Dalgleish
Contextures
www.contextures.com/tiptech.html
Blog: http://blog.contextures.com


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,979
Default If Pivot Table Exists, Delete on Close

That's the pivot table range, including the page fields.
TableRange1 does not include the page fields.

ryguy7272 wrote:
This seems to have worked very nicely. I have never used 'TableRange2'
before. What is this??? Please respond!!! I googled it and didn't find a
whole lot of information on 'TableRange2'...

Thanks for the help!
Ryan---



--
Debra Dalgleish
Contextures
www.contextures.com/tiptech.html
Blog: http://blog.contextures.com

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default If Pivot Table Exists, Delete on Close

Hello Debra,

Thanks for your simple and best answer, It helped me a lot
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
trying to delete a row in the pivot table for the pivot chart babs Excel Discussion (Misc queries) 3 April 2nd 23 07:10 PM
Determine If Pivot Table Exists ridawg Excel Programming 4 September 25th 06 08:55 PM
If Pivot Table Exists hoppermr Excel Programming 4 June 27th 06 05:47 PM
Im so close. Need variable range for the pivot table Loren[_2_] Excel Programming 1 October 5th 04 10:53 PM
Delete pivot table Zic[_2_] Excel Programming 2 May 25th 04 02:08 PM


All times are GMT +1. The time now is 04:55 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"