+ Reply to Thread
Results 1 to 5 of 5

Unprotecting and Reprotecting Workbook To allow macro to run

  1. #1
    Registered User
    Join Date
    02-18-2010
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    22

    Thumbs up Unprotecting and Reprotecting Workbook To allow macro to run

    Hi

    The attached file i need code inserted into vba to unprotect workbook allow the exisiting macro's to run, and re-protect on opening. To do the same in reverse on closure of workbook. I have tried various ways and fail each time.

    The macro alters the workbook structure so need it to unprotect to allow changes- re-protect so no one can change workbook structure whilst working on it on closing would need the workbook unprotected again allow the changes to happen again and re-protect.

    The attachment was supplied by RoyUK. See link http://www.excelforum.com/excel-prog...e-options.html

    Thank you in advance
    Attached Files Attached Files
    Last edited by Tictac; 02-25-2010 at 01:25 PM.

  2. #2
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Unprotecting and Reprotecting Workbook To allow macro to run

    In each macro add

    Activeworkbook.Unprotect
    'code
    Activeworkbook.Protect

    or

    Worksheets("Sheet 1").Unprotect Password:="Whatever"
    'code
    Worksheets("Sheet 1").Protect Password:="Whatever"

    etc
    Last edited by Marcol; 02-24-2010 at 10:56 PM.

  3. #3
    Registered User
    Join Date
    02-18-2010
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    22

    Re: Unprotecting and Reprotecting Workbook To allow macro to run

    Works great..Thank you. Just need to be able to use a password with it. Any thoughts?

    Much appreciated

  4. #4
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Unprotecting and Reprotecting Workbook To allow macro to run

    I tend not to use the Password option during development, it is bit of a pest when running code over and over again.
    Obviously you will have to use .Protect/.Unprotect during development to check that it works for you.

    You can also use
    Please Login or Register  to view this content.
    i.e. an empty string
    This will ask you for a password, don't enter anything in the inputbox, just click Okay/Enter.

    If you put anything in the inputbox, remember what it was, Excel certainly will!

    Finally, when you are ready, introduce your password, remember all the usual Password rules - case sensitive, illegal characters etc....
    You can use find/replace -

    Password:=""
    with
    Password:="Your Password"

    to fill throughout your code.

    Don't try mixing passwords in a project until you know what you are doing.

    I'm sure you will get the idea pretty quickly!

    P.S.

    It can be a good idea to password protect your VBa project when finished.
    This will prevent users opening your code and therefore finding the workbook/sheet passwords.

    Cheers
    Last edited by Marcol; 02-25-2010 at 07:56 AM. Reason: P.S. added

  5. #5
    Registered User
    Join Date
    02-18-2010
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    22

    Smile Re: Unprotecting and Reprotecting Workbook To allow macro to run

    Thank you so much it is greatly appreciated.

    SOLVED:

+ 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