Save/exit macro

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
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
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top