ActiveSheet.Protect Method RRS feed

  • Question

  • I have an excel sheet in which i'm programatically setting the protection using VBA. The issue is with the styles,font,Alignment etc sections in Home Tab are disabled when the line of code


    is executed which is expected because the default value for AllowFormattingCells is false. Image

    But immediately if i execute the below line of code

    ActiveSheet.Protect DrawingObjects:=False

    The above sections in Home tab are enabled back!!


    I know the solution for this problem that is to explicitly set the AllowFormattingCells to False along with the DrawingObjects but just curious to know the reason for excel VBA to behave this way.

    Monday, September 21, 2015 12:37 PM

All replies

  • I have seen this before and the answer is to set all of the parameters.

    It appears that if you don't set all parameters when setting a new parameter then the remaining parameters go to their default value.

    This is fairly normal behaviour for most optional parameters, if not specified then default value. I always make it a rule to not allow defaults anywhere in programming; specify the required values.

    Regards, OssieMac

    • Proposed as answer by David_JunFeng Monday, September 28, 2015 2:46 PM
    Tuesday, September 22, 2015 6:51 AM