+ Reply to Thread
Results 1 to 13 of 13

Protect specific sheets from deletion

  1. #1
    Registered User
    Join Date
    12-17-2007
    Posts
    14

    Protect specific sheets from deletion

    Is there anyway to prevent certain sheets from be deleted?

    i know there is protect workbook, but that prevents the user from deleting any sheet

  2. #2
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    See if example helps

    Code used

    In sheet1 module (right click sheet1 rab > select view code)
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Code in a normal module
    Please Login or Register  to view this content.
    VBA Noob
    Attached Files Attached Files
    Last edited by VBA Noob; 12-19-2007 at 04:14 PM.
    _________________________________________


    Credo Elvem ipsum etian vivere
    _________________________________________
    A message for cross posters

    Please remember to wrap code.

    Forum Rules

    Please add to your signature if you found this link helpful. Excel links !!!

  3. #3
    Registered User
    Join Date
    12-17-2007
    Posts
    14

    wow

    awesome, thanks man!

  4. #4
    Registered User
    Join Date
    12-17-2007
    Posts
    14
    so uh how do i turn it off? lol
    i ran it on a sheet i do want to be able to delete and can't figure it out ha

  5. #5
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Code is triggered when you select or unselected sheet1. Unselect sheet1 to turn off

    VBA Noob

  6. #6
    Registered User
    Join Date
    12-17-2007
    Posts
    14
    so uh, i tried making a new workbook entirely, and the macro followed it there

    for example, lets say i select sheet3, and then right click to try and delete, it pops open the excel with the preventdelete macro and doesn't allow me to do even if i disable macros

  7. #7
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Shouldn't work like that. Is it my example or your workbook

    VBA Noob

  8. #8
    Registered User
    Join Date
    12-17-2007
    Posts
    14
    well i had my workbook open
    and then i open your example, ran the macro
    and now it seems to have applied itself to ever other workbook lol

  9. #9
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Yes. As Sheet1 was still active in my example when you switched to the other workbook it would still be on.

    Try adding this code to thisworkbook module

    Please Login or Register  to view this content.
    VBA Noob

  10. #10
    Registered User
    Join Date
    12-17-2007
    Posts
    14
    OOOOOO okay
    i get it now
    in my other workbook i didn't have sheet 1 active but things still wouldn't delete and i was mad confused lol

    so in your code, where is it decide that if its sheet1 is active you can't delete
    because i want to try and edit your code so that it doesn't have to be sheet1, it could be for specific sheets that i don't one deleted
    like sheets 2, 3 and 7
    it'll be different for every user using my excel template

  11. #11
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    The code goes in the sheet module and is activated when you select the sheet. So if you add the code to say Sheet 1 and sheet 2 it will call the delete macro message and stop the user deleting either of those sheets

    VBA Noob

  12. #12
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    jubi23,

    Please read forum rules below and the message to cross posters then add the link to the cross post.

    VBA Noob

  13. #13
    Registered User
    Join Date
    12-17-2007
    Posts
    14
    ah okay, sorry about cross posting!
    never really thought about

    thanks again for all your help

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1