+ Reply to Thread
Results 1 to 4 of 4

Sheet Protection problem

  1. #1
    Forum Contributor
    Join Date
    11-20-2005
    Posts
    256

    Sheet Protection problem

    Hi all,

    This code does every thing i want it to, even though its not written well.
    The problem is if i use the line:

    '====> ActiveSheet.Protect 'Password:="12345"

    at the end, then the code hangs up, and i don't understand why as the code should be
    done running when the sheet is re-protected.

    If i don't use the line to reprotect the sheet then the code does what its supose to without eror.

    Error is --> "Unable to set the lineStyle Property of the Border Class"
    and its on the first ".LineStyle = xlDash" line.

    Please Login or Register  to view this content.
    Thx
    Dave
    "The game is afoot Watson"

  2. #2
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983
    It is because you are making changes to the sheet - Theses change trigger a new worksheet change event which causes the macro to run again.

    Use Application.EnableEvents=False at the start of the macro & Application.EnableEvents=True at the end.

    Note if the macro fails to get to the Application.EnableEvents=True command for any reason then any more changes to the sheet will not trigger the macro. If this occurs you will need to have another normal macro on the same sheet and run it manually.

    Please Login or Register  to view this content.

  3. #3
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259
    Hello Desert Piranha,

    The problem is once the worksheet is protected, the Worksheet_Change event is disabled and your code never runs. I modified your code a little and it runs. However I am not certain it runs the way you want it to. Here is the code...

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

  4. #4
    Forum Contributor
    Join Date
    11-20-2005
    Posts
    256
    Hi mudraker & Leith,

    Thank you so much for your input. Its working, with your sugestions.

    Thx again,
    Dave
    Quote Originally Posted by mudraker
    It is because you are making changes to the sheet - Theses change trigger a new worksheet change event which causes the macro to run again.

    Use Application.EnableEvents=False at the start of the macro & Application.EnableEvents=True at the end.

    Note if the macro fails to get to the Application.EnableEvents=True command for any reason then any more changes to the sheet will not trigger the macro. If this occurs you will need to have another normal macro on the same sheet and run it manually.


    Code:
    Sub ReEnable EventTriggers
    Application.EnableEvents=True
    End Sub
    Quote Originally Posted by Leith Ross
    Hello Desert Piranha,

    The problem is once the worksheet is protected, the Worksheet_Change event is disabled and your code never runs. I modified your code a little and it runs. However I am not certain it runs the way you want it to. Here is the code...

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

+ 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