+ Reply to Thread
Results 1 to 8 of 8

Need help with code adding password on every sheet in workbook

  1. #1
    Forum Contributor
    Join Date
    06-02-2014
    Location
    USA
    MS-Off Ver
    Office 365
    Posts
    235

    Need help with code adding password on every sheet in workbook

    i have created a code that's makes many loop throughs to different worksheets. The it currently locks and unlocks before it makes any modifications before macros (unlocking), then after macro (locking).. The issue is now I need to make it lock with a password. I have spent hrs on this.

    Any help is greatly appreciated!!

    Please Login or Register  to view this content.

  2. #2
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,913

    Re: Need help with code adding password on every sheet in workbook

    It would be easier to loop through the sheets in a workbook open event and protect each with a password and the UserInterfaceOnly option set to true.

    That way the VBA can still make changes to the worksheets without the need to unprotect / protect, but users will still be blocked from making their changes.

    Would that work for you?

    BSB

  3. #3
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,913

    Re: Need help with code adding password on every sheet in workbook

    Put this in the ThisWorkbook module:
    Please Login or Register  to view this content.
    BSB

  4. #4
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Need help with code adding password on every sheet in workbook

    Hi,

    Assuming you want the same password for all sheets, perhaps this
    Please Login or Register  to view this content.
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  5. #5
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Need help with code adding password on every sheet in workbook

    Just to add, BadlySpelledBuoy's solution is better if it works for what you're doing (userinterfaceonly does not work for everything), especially in newer versions of Excel where protecting and unprotecting is much slower. If it does work, you can remove the Unprotect and Protect lines from your existing code.

  6. #6
    Forum Contributor
    Join Date
    06-02-2014
    Location
    USA
    MS-Off Ver
    Office 365
    Posts
    235

    Re: Need help with code adding password on every sheet in workbook

    Ok this seemed to work. But i have another macro i need to do the same thing for and when i place that at the beginning it doesnt seem to work, here it is

    Please Login or Register  to view this content.

  7. #7
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,913

    Re: Need help with code adding password on every sheet in workbook

    Which suggested approach are you using?

    BSB

  8. #8
    Forum Contributor
    Join Date
    06-02-2014
    Location
    USA
    MS-Off Ver
    Office 365
    Posts
    235

    Re: Need help with code adding password on every sheet in workbook

    Actually this one worked best thx!!!

+ 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. [SOLVED] VBA code to update query from a password protected excel workbook and then close workbook
    By MrChipper in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-14-2017, 07:41 AM
  2. [SOLVED] VBA code in existing code to open when workbook encrypt with password.
    By deo_y in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-26-2014, 07:08 AM
  3. [SOLVED] adding password to workbook
    By nooredein in forum Excel General
    Replies: 4
    Last Post: 04-09-2014, 10:23 AM
  4. VBA code that bypass Password prompt for every workbook with one master password
    By pwnyadav007 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-22-2014, 01:45 AM
  5. unable to close password protected workbook using VBA code in another workbook
    By abulooz in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-04-2012, 08:54 AM
  6. Adding 'Password upon opening workbook' in VBA coding
    By Reayn in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-14-2011, 04:19 PM
  7. Adding Password Protection to code mods via VBA
    By realniceguy5000 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-24-2009, 01:36 PM

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