+ Reply to Thread
Results 1 to 4 of 4

Excel 2007 : unprotect and protect code for existing macro

  1. #1
    Forum Contributor
    Join Date
    04-20-2011
    Location
    Birmingham, England
    MS-Off Ver
    Excel 2007
    Posts
    121

    Smile unprotect and protect code for existing macro

    Ladies/Gents

    I have a Macro which unhides a worksheet, enters data, and hides it again.

    If I use a password, say "password", to protect the sheet can anyone give me a code I can add into my existing macro to unprotect and re protect with "Password"?

    If there is a simple code I will add it in, or will send you the existing code if required.

    Help much appreciated,

    Martin (Chambo)


    Thanks. I have worked it out from your code and managed to get the result.
    Last edited by Martin Chamberlin; 11-25-2011 at 04:05 PM. Reason: Solved it
    Chambo1160

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,447

    Re: unprotect and protect code for existing macro

    Please Login or Register  to view this content.

    You can also refer to specific sheets, etc


    Regards
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Contributor
    Join Date
    04-20-2011
    Location
    Birmingham, England
    MS-Off Ver
    Excel 2007
    Posts
    121

    Re: unprotect and protect code for existing macro

    Its getting close but not there. Heres the code. It goes to debug when I run it
    [Sub Macro2()

    Dim LastRow As Double

    Sheets("Enter Data").Select
    Sheets("Archive").Visible = True
    ActiveSheet.Unprotect Password:="tmd"
    Sheets("Enter Data").Select
    ActiveCell.Offset(1, 0).Range("A1").Select
    Sheets("Enter Data").Select
    Range("a1:c1").Select
    Selection.Copy

    Sheets("Archive").Select
    LastRow = Cells(Rows.Count, "A").End(xlUp).Row
    Cells(LastRow + 1, "A").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False

    Sheets("Enter Data").Select
    Range("A2").Select
    Application.CutCopyMode = False
    Sheets("Archive").Select
    ActiveWindow.SelectedSheets.Visible = False
    End Sub]

    It stops at Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False

    Thanks for the help so far.

    Chambo

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,447

    Re: unprotect and protect code for existing macro

    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

+ 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