Jeremy
Unless of course what you want to do is part of a larger macro, is a macro really necessary?
It does not take long to perform the following steps :-
1.Save the file as a new filename and then delete the sheets "Main" and "Data" from the new file.
2.Open the original file and delete all sheets except "Main" and "Data"
Celia
Unfortunatly it is part of a process of Macros.
Is there a way to deal?
J.H
Jack
The following should do it (but there is probably a simpler way) :-
Sub MoveWorksheets()
Dim originalWB As Workbook, sheet As Worksheet, response As Boolean
Set originalWB = ActiveWorkbook
'Copy all sheets to a new workbook
Worksheets.Copy
'Turn off alerts
Application.DisplayAlerts = False
'Delete sheets Data and Main from the new workbook
Sheets(Array("Data", "Main")).Delete
'Display SaveAs dialog box
response = Application.Dialogs(xlDialogSaveAs).Show
'Check that Cancel or Close was not selected
If response = False Then
MsgBox "You MUST save the new file." & Chr(13) & Chr(13) & "Run the macro again."
ActiveWorkbook.Close savechanges:=False
Exit Sub
End If
'Go back to original workbook
originalWB.Activate
'Delete all sheets except Data and Main
For Each sheet In Worksheets
If sheet.Name <> "Data" Then
If sheet.Name <> "Main" Then
sheet.Delete
End If
End If
Next
'Turn on alerts
Application.DisplayAlerts = True
End Sub
Celia
Celia, It worked like a dream.
Cheers.
You've got me out of the Rutt.
Thanks.