Hi folks,
DaveInIowa, I agree with you. I tried again with anotherhiggins and ettienne's code on diff. workbooks. Sometimes it works and sometimes it does not. I don't think it has anything to do with tabs being hidden or not; as for tabs having been deleted, it should be true.
Looks like you guys are really serious about my questions and I'd thank you for that. Let me tell you what's going on with my work and I'll try to cut a long story short.
I have a bunch of monthly reports (about 20). Each has a size of 20 to 60 MG before zip, and each has 7 tabs visible (I call them showtabs) but the data tabs behind 7 tabs are hidden.
Because of the size of the workbooks, it's impossible to send them to the clients by email (we use Lotus Notes) since anything emailable must be <= 10 MG and 240 Bytes after zipping. Mine are way over it.
Some clients want only one showtab or part of the workbooks. So I can make it possible to send them by email by deleting all the irrelevant tabs and keep only about 10 tabs which support the single showtab.
Here is what I did.
1) using the macro to list all the tabs in the workbook on a spread sheet;
2) manually delete the tab names that I don't want to keep (or delete the names that I want to keep);
3) cut and paste the names to a SAS (hope you heard of it) pgm and SAS will create a Excel macro like the following in a fraction of a second:
Sub DeleteMost()
Application.DisplayAlerts = False
For Each s In Worksheets
If InStr(s.Name, "Graph_ARB") = 0 And _
InStr(s.Name, "med_ind") = 0 And _
InStr(s.Name, "export_stategraphdata") = 0 And _
InStr(s.Name, "district_name") = 0 And _
InStr(s.Name, "Terr_Payer") = 0 And _
InStr(s.Name, "export_terr_data") = 0 And _
InStr(s.Name, "distpayerlist") = 0 And _
InStr(s.Name, "MonthList") = 0 And _
InStr(s.Name, "Export_State_Natn") = 0 And _
InStr(s.Name, "Export_State_Summ") = 0 And _
InStr(s.Name, "territory_name") = 0 And _
InStr(s.Name, "regionlist") = 0 And _
InStr(s.Name, "export_payer_data") = 0 And _
InStr(s.Name, "Graph_AHY") = 0 Then s.Delete
Next
Application.DisplayAlerts = True
End Sub
Or:
Sub DeleteMost()
Application.DisplayAlerts = False
For Each s In Worksheets
If s.Name <> "Graph_ARB" And _
s.Name <> "med_ind" And _
s.Name <> "export_stategraphdata" And _
s.Name <> "district_name" And _
s.Name <> "Terr_Payer" And _
s.Name <> "export_terr_data" And _
s.Name <> "distpayerlist" And _
s.Name <> "MonthList" And _
s.Name <> "Export_State_Natn" And _
s.Name <> "Export_State_Summ" And _
s.Name <> "territory_name" And _
s.Name <> "regionlist" And _
s.Name <> "export_payer_data" And _
s.Name <> "Graph_AHY" Then s.Delete
Next
Application.DisplayAlerts = True
End Sub
4) I run this macro so the workbook will shrink and be ready for email delivery.
Hope I made myself understood and didn't bore you.
As a matter of fact, I was trying to find out if Select Case can do the same job as IF/AND statements. [blue]Some of you folks may say: why don't you delete the tab names you want keep in the 2) step, and then Sub Deletemost() would be like
...
Select Case s.Name
case "tab2","tab10",...,"tab5","tab25"
s.delete
...
instead of going through the pain 'Case Not....'.
I agree with you 100%. But somehow I'd like to a visual at the tabs that I'm keeping, and I don't want the Sub becomes lengthy.[/blue]
Thanks again.
It's nice to talk with the folks in the forum and this is a great forum.