|
-
May 16th, 2008, 11:13 AM
#1
[RESOLVED] Excel VBA - Delete Sheet Disabled
Can someone explain why Edit/Delete Sheet is disabled in a workbook that is not protected in any way?
I need to delete a sheet, and delete is disabled both in the right click popup menu and the menu item under Edit.
-
May 16th, 2008, 04:04 PM
#2
Re: Excel VBA - Delete Sheet Disabled
what error do you get if you try to delete with code?
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
May 16th, 2008, 05:53 PM
#3
Re: Excel VBA - Delete Sheet Disabled
A sheet cannot be deleted if it is the last visible sheet or the workbook is protected in some way.
Are you sure "workbook that is not protected"? Is the workbook shared?
-
May 17th, 2008, 12:19 AM
#4
Re: Excel VBA - Delete Sheet Disabled
A sheet cannot be deleted if it is the last visible sheet
i checked this, in excel 2000, it does not disable the menu item, just brings up a dialog if you try to delete
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
May 17th, 2008, 05:02 AM
#5
Re: Excel VBA - Delete Sheet Disabled
The workbook is not shared.
The sheet is not the last in the workbook (in fact, there are a whole lot of sheets and need to go. This is just one of several - I got this app dumped in my lap cause the guy who did it retired, and it needed fixing.)
I have not attempted to delete it through code, and do not want to. There is no reason to do this through code as that code would only need to be run a single time. Once this sheet is deleted, it will never been recreated. The sheet was used to populate a dropdown. I'm populating the dropdown with code, so there is no reason at all for this sheet to exist (all of the controls on the workbook are being populated with different sheets and I'm replacing them all with code, so there are about 6 or 7 sheets that I want to completely, totally, and forever delete from the workbook.
However, the delete options from the menus remain disabled.
-
May 17th, 2008, 07:17 AM
#6
Re: Excel VBA - Delete Sheet Disabled
One thing may happens is the author of the workbook may use code to disable the delete menu and command. You may find the code some where in VBE.
Try this: Open the workbook with Macro Disabled then try to delete the sheets to see if it works.
-
May 17th, 2008, 08:14 AM
#7
Re: Excel VBA - Delete Sheet Disabled
I definitely get the Delete menus disabled when the workbook (but not the worksheet) is protected. You will also be unable to move sheets around, insert new ones (etc) if the workbook structure is protected.
To be certain, if on the Tools -> Protection menu it says "Unprotect workbook", then it has been protected. Notice that you may have the sheets Unprotected but the workbook protected.
If you're certain that the workbook is not protected, then it's definitely unusual. Can you post it, or is it confidential?
-
May 17th, 2008, 02:32 PM
#8
Re: Excel VBA - Delete Sheet Disabled
 Originally Posted by anhn
Try this: Open the workbook with Macro Disabled then try to delete the sheets to see if it works.
 Originally Posted by zaza
To be certain, if on the Tools -> Protection menu it says "Unprotect workbook", then it has been protected. Notice that you may have the sheets Unprotected but the workbook protected.
Thanks guys. I will check this out on Monday.....I hadn't thought about the disable macros thing, and I did not know there was a difference between workbook and sheet protection.
zaza: You say the a sheet could be unprotected but the workbook protected. Is it possible to have the reverse...i.e., the workbook unprotected, but the sheet protected?
-
May 17th, 2008, 06:29 PM
#9
Re: Excel VBA - Delete Sheet Disabled
you can run a single line of code to delete a sheet from the intermediate window
i was just interested what if any error message you got, as it may have pointed to the reason for the menu being disabled, but it turns out the message is just generic
sheets("sheetname").delete
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
May 17th, 2008, 07:46 PM
#10
Re: Excel VBA - Delete Sheet Disabled
 Originally Posted by Hack
Thanks guys. I will check this out on Monday.....I hadn't thought about the disable macros thing, and I did not know there was a difference between workbook and sheet protection.
zaza: You say the a sheet could be unprotected but the workbook protected. Is it possible to have the reverse...i.e., the workbook unprotected, but the sheet protected?
Yes, definitely. The workbook protection is to protect the structure of the workbook without necessarily interfering with what the user can do on the sheets. It will prevent you from inserting or deleting sheets or moving their order, for example, but won't stop you typing in cells or changing formatting.
Sheet protection will stop you from overtyping formulas, changing cells etc on individual sheets, but won't stop you from adding extra sheets in or rearranging them. Either and both can be password protected, but don't have to be in order to be protected.
-
May 19th, 2008, 01:02 PM
#11
Re: Excel VBA - Delete Sheet Disabled
Disabling the macros didn't work.
I also can't upload it. Even zipped, it exceeds the attachment file limit.
-
May 19th, 2008, 03:44 PM
#12
Re: Excel VBA - Delete Sheet Disabled
What about double-checking the protection?
-
May 20th, 2008, 06:53 AM
#13
Re: Excel VBA - Delete Sheet Disabled
 Originally Posted by zaza
What about double-checking the protection?
As it turns out, it is protected. As least, I think it is protected.
I thought this not to be the case, because the "Tools/Protection/Protect Sheet" menu item is enabled. I was told, or read somewhere, that if protection is on, then that will be disabled, and "Unprotect Workbook" will be enabled. Oddly enough, they are both enabled. When I click "Unprotect Workbook" however, it asks me for a password (which none of use have any clue what it might be - the author of this "application" retired).
Just to verify - if I click Unprotect Workbook and it asks for a password, then that means it is protected, right?
If so, then why is Protect Sheet still enabled? Isn't it already protected? How can you protect the same thing twice?
-
May 20th, 2008, 07:17 AM
#14
Re: Excel VBA - Delete Sheet Disabled
That's odd enough.
If a menu item shown "Protect Sheet/Workbook" that means Sheet/Workbook is not protected.
If a menu item shown "Unprotect Sheet/Workbook" that means Sheet/Workbook was protected.
If the sheet is protected but the workbook is not protected then you can delete the sheet.
However, if the sheet is not protected but the workbook is protected then you CANNOT delete the sheet.
Try this way:
Step 1: In VBE, drag any existing forms and modules from old workbook to a new workbook.
Step 2: Select all sheets then use option "Copy or Move" : Copy all sheets to a new workbook.
This method may have a problem with linked cells from this sheet to another sheet but you can change links later.
Sheet and workbook paswords are relative easy to break with some tools (you can find out ...), only openning password is hard to break.
Last edited by anhn; May 20th, 2008 at 07:21 AM.
-
May 20th, 2008, 12:08 PM
#15
Re: Excel VBA - Delete Sheet Disabled
 Originally Posted by anhn
If a menu item shown "Protect Sheet/Workbook" that means Sheet/Workbook is not protected.
If a menu item shown "Unprotect Sheet/Workbook" that means Sheet/Workbook was protected.
That is exactly what I thought, yet, it was protected, but Protect Sheet was still enabled.
 Originally Posted by anhn
Sheet and workbook paswords are relative easy to break with some tools
One of the Excel guys back in my shop managed to break it, so I got it unprotected, and could delete the sheet. However, it remains a mystery with respect to how it got protected and still the associated menu items remained enabled.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|