Thread: deleting sheet
View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Seeker Seeker is offline
external usenet poster
 
Posts: 137
Default deleting sheet

Hi Jacob,
I added the code in my first post to Private Sub Workbook_BeforeClose(Cancel
As Boolean), the sheet was deleted before book closed, thats great.
I have problem in the Sheet DeActivate event. The event code is attached to
the sheet when I built it - say Sheet1(Print), when changing tab, it only
works once, thereafter, code crash.
1) As Print sheet is added by macro upon request only, the sheet number
changes from Sheet1(Print) to Sheet2(Print) and so on, so the code cannot be
kept and attached to the new added (Print).
2) If I close the work book while I am on the Print page, both
€śWorkbook_BeforeClose€ť and €śSheet DeActivate event€ť activate at the same time
caused one of the €śdelete€ť action cannot be performed.
Any solution to solve this please?
Rgds

"Jacob Skaria" wrote:

Try the Workbook close event..From VBE double click 'ThisWorkbook'

Private Sub Workbook_BeforeClose(Cancel As Boolean)

OR

get the Sheet DeActivate event of the 3rd sheet
Private Sub Worksheet_Deactivate()


If this post helps click Yes
---------------
Jacob Skaria


"Seeker" wrote:

I have a workbook with 3 work sheets, first tab is for data input, second tab
is for data maintain, third tab is macro auto add sheet which extract data
from data maintain sheet for reporting purpose. I would like to delete the
third sheet when either users switch to other tab or closing workbook. I get
the €śdelete€ť code but dont know the code when users switch tab or close book.

Application.DisplayAlerts = False
Sheets("Print").Delete
Application.DisplayAlerts = True