Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Workbook before close

I want to delete two sheets before the file is closed everytime.

I had writen some similar code before, but I can't remember it and this time
it doesn't work. I must have something wrong here.

Private Sub WorkbookBeforeClose(ByVal Wb As Workbook, _
Cancel As Boolean)

Sheets("Summary").Select

Sheets("Sheet2").Select

End Sub


By the way, when before the sheets are deleted it always asks you to
confirm. Is it possible to put in a line to make the confirmation automatical?

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Workbook before close

Maybe this

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Application.DisplayAlerts = False
Sheets("Summary").Delete
Sheets("Sheet2").Delete
Application.DisplayAlerts = True
End Sub

Mike

"jwang036" wrote:

I want to delete two sheets before the file is closed everytime.

I had writen some similar code before, but I can't remember it and this time
it doesn't work. I must have something wrong here.

Private Sub WorkbookBeforeClose(ByVal Wb As Workbook, _
Cancel As Boolean)

Sheets("Summary").Select

Sheets("Sheet2").Select

End Sub


By the way, when before the sheets are deleted it always asks you to
confirm. Is it possible to put in a line to make the confirmation automatical?

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Workbook before close

Thanks! It works well.

Now I have a new problem. I have a button to add sheet1 & summary to
summarise some calculations. Then they will be deleted everytime when the
file is closed. However, if the user doesn't click the button and close the
file the error appears as the sheets are not there. I am trying to add the
"if then" code to judge if the sheets exist or not first. But I'm not very
good with VB and if you see this reply I believe you will be much quicker to
solve this problem. Thanks in advance.


€œMike H€ç¼–写:

Maybe this

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Application.DisplayAlerts = False
Sheets("Summary").Delete
Sheets("Sheet2").Delete
Application.DisplayAlerts = True
End Sub

Mike

"jwang036" wrote:

I want to delete two sheets before the file is closed everytime.

I had writen some similar code before, but I can't remember it and this time
it doesn't work. I must have something wrong here.

Private Sub WorkbookBeforeClose(ByVal Wb As Workbook, _
Cancel As Boolean)

Sheets("Summary").Select

Sheets("Sheet2").Select

End Sub


By the way, when before the sheets are deleted it always asks you to
confirm. Is it possible to put in a line to make the confirmation automatical?

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
Hide all Sheets in Workbook then Close Workbook RyanH Excel Programming 0 January 29th 08 12:59 PM
Open New Workbook / Save and Close Current Workbook Joe K. Excel Programming 1 December 7th 07 08:04 PM
Closing a workbook from a macro doesn't close the workbook Dave P Excel Programming 2 July 10th 07 06:16 PM
Help on Workbook close and workbook save events Adam Harding Excel Programming 1 September 29th 05 04:12 PM
Close a the current workbook and load another specified workbook Adrian[_7_] Excel Programming 4 August 7th 04 05:29 PM


All times are GMT +1. The time now is 01:33 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"