Closed Thread
Results 1 to 6 of 6

VBA Code to Unprotect a Worksheet then Protect

  1. #1
    Registered User
    Join Date
    03-24-2011
    Location
    Fort Wayne, IN
    MS-Off Ver
    Excel 2007
    Posts
    12

    VBA Code to Unprotect a Worksheet then Protect

    Hi,
    I have created a form with Macro in it and have locked cells so you can tab thru each cell easily. I protected the workbook but the problem is that when I run the macros it gives me an error because I have to the workbook protected.

    I am looking for a VBA code that when I run one of my macros it will UNPROTECT the sheet, run the macro and then go back and Protect it.

    Can someone help?

    Thank you!

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: VBA Code to Unprotect a Worksheet then Protect

    Please Login or Register  to view this content.
    Or look at Protection wuith UserInterface
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Registered User
    Join Date
    03-24-2011
    Location
    Fort Wayne, IN
    MS-Off Ver
    Excel 2007
    Posts
    12

    Re: VBA Code to Unprotect a Worksheet then Protect

    I forgot to mention that the macro is running off of Sheet 2 and putting in the information in Sheet 1.
    In the code I need it to Unprotect Sheet 1 run the code then Proctect sheet 1 again.

    Thank you!

  4. #4
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: VBA Code to Unprotect a Worksheet then Protect

    Simple enough, replace ActiveSheet with Sheet1

  5. #5
    Registered User
    Join Date
    10-23-2011
    Location
    Florence, SC
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: VBA Code to Unprotect a Worksheet then Protect

    Hello. I am working on a time clock program for my company. I need some assistance in figuring out how to write a code so that a cell is locked, then unlocked when a button is pressed to record the time, then locked again. I have this process already set up; however, I cannot figure out a way to only have this process be performed once. Right now, if the associate presses the button, the time will continue to be replaced. Below is the code I have for one of the buttons. Any help will be greatly appreciated!

    Sub AA()
    Range("D5").Select
    ActiveSheet.Unprotect ("8827")
    ActiveCell.Value = Format(Now, "'HH:MM AM/PM")
    ActiveSheet.Protect ("8827")
    ActiveWorkbook.SaveAs Filename:=Range("B6").Value
    End Sub

  6. #6
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: VBA Code to Unprotect a Worksheet then Protect

    Welcome to the Forum, unfortunately your first post has broken 2 rules. You need to read the Forum Rules

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here

    Your post does not comply with Rule 2 of our Forum RULES. Don't post a question in the thread of another member -- start your own thread. If you feel it's particularly relevant, provide a link to the other thread.

Closed 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