Events

hatman

Well-known Member
Joined
Apr 8, 2005
Messages
2,664
I have a workbook that has two levels of users: 1)Peon 2)Administrator. A custom toolbar gets generated when the book is activated, and the buttons that populate it depend on whether the user's name appears in the Admin list. One of these buttons allows the admin to add a new sheet, with a whole bunch of additional activities to link the new sheet with all of the others. I am currently using code in the NewSheet event to delete new sheets as they get added using any method other that my admin button. And this works VERY well.

The thing is that I WANT the admin to be able to able to add sheets, delete sheets, rename sheets or move sheets. There should be no restrictions on moving or renaming sheets, but adding or deleting sheets needs to happen through macros that handle the required set of operations.

My problem is preventing someone from deleting a sheet through an avenue other than my admin button. There is no event that seems to fire for deleting a sheet. I have tried defining a new event using the WithEvents declaration in a class module, but can't seem to locate or define the SheetDelete event.

I have toyed with protecting the workbook structure, and simply unprotecting the workbook in the macro to allow the macro to do the sheet manipulation... but that turns off the SheetRename and SheetMove options... I suppose that I can simply write 2 more macros to perform these functions after unprotecting the book programmatically, but it seems like there ought to be a more elegant solution without cluttering my toolbar with even more buttons.

Any suggestions would be greatly appreciated... perhaps I already have my solution, even though it isn't as clean as I would like, but since there always seems to be more that you guys know, I figured I'd pose the question.
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Hi hatman,

Why not just disable the standard buttons and menu items (including the shortcut dropdown menu) that perform the sheet add and delete functions?

Damon
 
Upvote 0
That works for people who use buttons and menus, but what about right mouse click on the sheet tab? That would still be accessible.
 
Upvote 0
Hi again hatman,

Yes, you're right. That's what I was referring to by the shortcut dropdown menu. Actually, the Excel object model treats this just as it does other CommandBars. The sheet tab dropdown is actually a CommandBar named "Ply". Execute

CommandBars("Ply").ShowPopup

in the Immediate window of the VBE and you will see what I mean. You can disable buttons on this commandbar the same as you would any other.

Damon
 
Upvote 0
Well I learned something new. I will look into that... it does seem like it would be a more elegant solution than what I am doing now.

Thanx for your help!
 
Upvote 0

Forum statistics

Threads
1,224,315
Messages
6,177,841
Members
452,809
Latest member
mar_luna

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top