Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default Save/exit macro

hello all (again).
Im currently using this code below for exiting my system

Sub Save_Exit()
Application.Quit
ThisWorkbook.Close SaveChanges:=True
End Sub

Pretty simple i know, but what i really really need is some way of saving
the workbook but deleting all of the worksheets apart from "Worksheet 1". If
anyone can help me i will be very grateful. Thanks a bunch.
Andrew

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Save/exit macro

Hi,

This will delete everything except the name sheet

Sub versive()
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
If ws.Name < ("Sheet5") Then ws.Delete 'Change to suit
Next ws
End Sub

It will generate an alert for each sheet, if you want to eliminate that add
this around the code:-

Application.displatalerts=false


Application.displayalerts=true

Mike

"andrewbt" wrote:

hello all (again).
Im currently using this code below for exiting my system

Sub Save_Exit()
Application.Quit
ThisWorkbook.Close SaveChanges:=True
End Sub

Pretty simple i know, but what i really really need is some way of saving
the workbook but deleting all of the worksheets apart from "Worksheet 1". If
anyone can help me i will be very grateful. Thanks a bunch.
Andrew

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 43
Default Save/exit macro

See if this does it for you:

Sub foo()
Dim i As Long
Dim ws As Worksheet
i = 2
For Each ws In ActiveWorkbook.Worksheets
Application.DisplayAlerts = False
If Sheets.Count = 1 Then Exit Sub
Worksheets(i).Delete
i = i + 1
Application.DisplayAlerts = True
Next ws
End Sub

HTH,

Smitty

"Mike H" wrote:

Hi,

This will delete everything except the name sheet

Sub versive()
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
If ws.Name < ("Sheet5") Then ws.Delete 'Change to suit
Next ws
End Sub

It will generate an alert for each sheet, if you want to eliminate that add
this around the code:-

Application.displatalerts=false


Application.displayalerts=true

Mike

"andrewbt" wrote:

hello all (again).
Im currently using this code below for exiting my system

Sub Save_Exit()
Application.Quit
ThisWorkbook.Close SaveChanges:=True
End Sub

Pretty simple i know, but what i really really need is some way of saving
the workbook but deleting all of the worksheets apart from "Worksheet 1". If
anyone can help me i will be very grateful. Thanks a bunch.
Andrew

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
Excel Save as & Exit macro [email protected] Excel Programming 0 July 26th 07 07:50 AM
running macro at save/close/exit Pedro Excel Programming 1 August 31st 06 07:03 PM
Write macro don't ask to save when exit excel Rui Alvares Excel Programming 0 March 29th 06 12:50 AM
Macro: Exit active workbook without save? Don Excel Worksheet Functions 0 May 20th 05 06:47 AM
Save & Exit Anthony Excel Worksheet Functions 1 February 12th 05 05:23 PM


All times are GMT +1. The time now is 09:35 AM.

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

About Us

"It's about Microsoft Excel"