本文介绍了ActiveSheet.Protect方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一张excel表,其中我使用VBA以编程方式设置保护。当代码行

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

 ActiveSheet.Protect


,这是因为AllowFormattingCells的默认值为false。 

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

但是如果我执行下面的代码行

But immediately if i execute the below line of code

ActiveSheet.Protect DrawingObjects:=False


"主页"选项卡中的上述部分已启用!!

The above sections in Home tab are enabled back!!

我知道这个问题的解决方案是将AllowFormattingCells显式设置为False和DrawingObjects一起,但只是很想知道excel VBA以这种方式表现的原因。

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.

推荐答案

如果在设置新参数时未设置所有参数,则其余参数将显示为其默认值。

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.


这篇关于ActiveSheet.Protect方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 14:12