+ Reply to Thread
Results 1 to 10 of 10

Complicated VBA code to protect the entire workbook (in a single step)

  1. #1
    Forum Contributor Anka's Avatar
    Join Date
    08-25-2012
    Location
    Lisbon
    MS-Off Ver
    Excel 2016
    Posts
    174

    Complicated VBA code to protect the entire workbook (in a single step)

    Hello friends.

    I made a workbook and trying to protect. I was able to find some VBA code similar to what I need, but I fail to put them together (lack of experience).
    So what I need.
    1. I want to protect existing VBA Code in all worksheets.
    2. I want to protect all formulas (to hide) in all existing worksheets.
    3. If in any worksheet in cell A1 appears something then, automatically remove all sheets except the first sheet, and automatically save the entire workbook.
    4. I want to deny users to change certain cells in certain sheets, but I think it is a little complicated because I have filtered columns, some hidden, and VBA code active in the sheets.
    However, if it is possible to put together the first three points, I think it is enough.
    It is possible to be done in a single step?
    Any help is welcome.
    Thanks in advance

    PS: My English is still very poor...
    Many thanks to all who have helped me.

  2. #2
    Forum Contributor Anka's Avatar
    Join Date
    08-25-2012
    Location
    Lisbon
    MS-Off Ver
    Excel 2016
    Posts
    174

    Re: Complicated VBA code to protect the entire workbook (in a single step)

    A little help ..

  3. #3
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Complicated VBA code to protect the entire workbook (in a single step)

    Hi, Anka,

    I was able to find some VBA code similar to what I need, but I fail to put them together (lack of experience).
    Please attach a sample workbook with these codes in order to make it easier for us to answer.

    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  4. #4
    Forum Contributor Anka's Avatar
    Join Date
    08-25-2012
    Location
    Lisbon
    MS-Off Ver
    Excel 2016
    Posts
    174

    Re: Complicated VBA code to protect the entire workbook (in a single step)

    Thanks for your interest HaHoBe.
    I managed to "polish" a bit, but I think is not really ok. I wants this.
    3. If in any worksheet in cell A1 appears something then, automatically remove all sheets except the first sheet, and automatically save the entire workbook.
    "Mine" macro work just in first sheet...

    Thanks again.

    Example.xlsm

  5. #5
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Complicated VBA code to protect the entire workbook (in a single step)

    Hi, Anka,

    the procedure Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range) should not be located in Module2 but in ThisWorkbook as only there it would get fired from the event.

    Code goes into ThisWorkbook (and please use a copy of the workbook to test), code will get fired when any value is entered into any sheet (except Info):
    Please Login or Register  to view this content.
    Ciao,
    Holger

  6. #6
    Forum Contributor Anka's Avatar
    Join Date
    08-25-2012
    Location
    Lisbon
    MS-Off Ver
    Excel 2016
    Posts
    174

    Re: Complicated VBA code to protect the entire workbook (in a single step)

    Holger, thanks for your answer, but what I want is;
    3. If in any worksheet, including Sheet1 what in my case is called Info, in cell A1 appears something(text or numbers) then, automatically remove all sheets except the first sheet (Info), and automatically save the entire workbook.

    Anyway thank you again.

  7. #7
    Forum Contributor Anka's Avatar
    Join Date
    08-25-2012
    Location
    Lisbon
    MS-Off Ver
    Excel 2016
    Posts
    174

    Re: Complicated VBA code to protect the entire workbook (in a single step)

    Holger, thanks for your answer, but what I want is;
    3. If in any worksheet, including Sheet1 what in my case is called Info, in cell A1 appears something(text or numbers) then, automatically remove all sheets except the first sheet (Info), and automatically save the entire workbook.

    Anyway thank you again.

  8. #8
    Forum Contributor Anka's Avatar
    Join Date
    08-25-2012
    Location
    Lisbon
    MS-Off Ver
    Excel 2016
    Posts
    174

    Re: Complicated VBA code to protect the entire workbook (in a single step)

    I'm sorry for repeating it ...

  9. #9
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Complicated VBA code to protect the entire workbook (in a single step)

    Hi, Anka,

    I'm sorry for repeating it ...
    forum issues.

    Maybe try it like this:
    Please Login or Register  to view this content.
    Ciao,
    Holger

  10. #10
    Forum Contributor Anka's Avatar
    Join Date
    08-25-2012
    Location
    Lisbon
    MS-Off Ver
    Excel 2016
    Posts
    174

    Re: Complicated VBA code to protect the entire workbook (in a single step)

    I apologize for the delayed response.
    Yes HaHoBe, it works.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Protect/unprotect formula cells of entire workbook
    By shafiqe in forum Excel General
    Replies: 5
    Last Post: 07-14-2013, 01:59 AM
  2. How to protect entire excel workbook with running macros?
    By anjoseph9626 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-28-2013, 08:18 AM
  3. Protect entire workbook
    By dwarford101 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-13-2010, 06:07 AM
  4. How to protect desired area of workbook and protect code.
    By avveerkar in forum Excel General
    Replies: 4
    Last Post: 01-12-2006, 10:44 PM
  5. Replies: 5
    Last Post: 08-09-2005, 11:05 AM

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