![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Board Regular
Join Date: Feb 2002
Location: Georgia USA
Posts: 544
|
Is there a way to keep for deleting a sheet from a workbook, I have a sheet named "Data" that I don't want someone to accidentally delete, protecting the workbook is not a option, sheets need to be put in and deleted all the time, just want to make sure that the "data" sheet is not deleted. maybe something like before delet? Thanks for your help
|
|
|
|
|
|
#2 |
|
Board Regular
Join Date: Feb 2002
Location: Brisbane, Down Under
Posts: 533
|
Protect just the "Data" sheet not the whole workbook.
|
|
|
|
|
|
#3 | |
|
Guest
Posts: n/a
|
protects the data, but won't prevent the sheet from being deleted.
Quote:
|
|
|
|
|
#4 |
|
Board Regular
Join Date: Feb 2002
Location: Georgia USA
Posts: 544
|
Yes just the sheet named "Data" sheet not the whole workbook
|
|
|
|
|
|
#5 |
|
Board Regular
Join Date: Feb 2002
Location: Brisbane, Down Under
Posts: 533
|
should have tried it first - sounds like some vba code is needed in the workbook module, tried a few things but couldn't get it to work
|
|
|
|
|
|
#6 |
|
New Member
Join Date: Feb 2002
Location: Washington State
Posts: 33
|
This code will grey out the delete sheet option on all toolbars and also if you right click the sheet tab. Right click on the DATA sheet tab, choose VIEW CODE from that menu, and paste this code into the VBE. Thanks to Ivan for showing me the Control ID method of deleting menu items.
Private Sub Worksheet_Activate() ID = 847 For Each CB In Application.CommandBars Set C = CB.FindControl(ID:=ID, recursive:=True) If Not C Is Nothing Then C.Enabled = False Next End Sub Hope this helps Rick |
|
|
|
|
|
#7 |
|
Board Regular
Join Date: Feb 2002
Location: Georgia USA
Posts: 544
|
the code below makes it so you can't delete any of the sheets, I need it to work on only the one named "Data". can it be changed to do that?
Private Sub Worksheet_Activate() ID = 847 For Each CB In Application.CommandBars Set C = CB.FindControl(ID:=ID, recursive:=True) If Not C Is Nothing Then C.Enabled = False Next End Sub |
|
|
|
|
|
#8 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Allentown, PA
Posts: 2,510
|
Paul:
If you have put that code into the Workbook or into a module, it will work on all sheets (I believe--someone please correct me if I'm wrong). You need to double-click the Data sheet in the VB editor window and paste it THERE only. You'll need to remove it from the ThisWorkbook or from a module if it is there. Then test. Good luck.
__________________
~Anne Troy |
|
|
|
|
|
#9 |
|
Board Regular
Join Date: Feb 2002
Location: Georgia USA
Posts: 544
|
I put it in the worksheet code, but its worst that I thought now I can't delete ANY SHEET IN ANY WORKBOOK, how do I change it back. I have deleted the code saved the book closed excel, restarted excel, I still can't delete ANY sheets.Help!
|
|
|
|
|
|
#10 |
|
Banned
Join Date: Feb 2002
Posts: 1,582
|
Hi Paul
Seems like this has caused grief for a number of Excel users. I recenlty answered this for another person here: http://mrexcel.com/board/viewtopic.p...1862&forum=2&2 |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|