在VBA Excel中,如果我在关闭并再次打开文件后使用UserInterFaceOnly:=True选项保护工作表,则UserInterFaceOnly模式不处于活动状态,仅密码保护.
In VBA Excel if I protect sheets with UserInterFaceOnly:=True option after I close and open the file again the UserInterFaceOnly mode is not active, only Password protection.
代码:ActiveSheet.Protect Password:="myPassword", UserInterfaceOnly:=True
为什么?
推荐答案重新打开工作簿后,如果不重新应用UserInterfaceOnly:=True,您将无法做到这一点.取自Excel的Vb 保护方法参考:
You can't do it without reapplying UserInterfaceOnly:=True after reopening the workbook. Taken from Excel's Vb protect method reference:
如果在UserInterfaceOnly参数设置为true的情况下应用此方法,然后保存工作簿,则当您重新打开工作簿时,整个工作表(而不仅仅是接口)将受到完全保护.要在打开工作簿后重新启用用户界面保护,必须在UserInterfaceOnly设置为true的情况下再次应用此方法
If you apply this method with the UserInterfaceOnly argument set to true and then save the workbook, the entire worksheet (not just the interface) will be fully protected when you reopen the workbook. To re-enable the user interface protection after the workbook is opened, you must again apply this method with UserInterfaceOnly set to true
现在,如果您担心此过程花费的时间太长(如您所说的15秒),请查看此代码查看答案.我已经在几本复杂程度各异的工作簿中做到了这一点,并且在我尝试过的所有版本(包括2010年)中,重新应用保护的时间都可以忽略不计.
Now, if your concern is that this takes too long (15 seconds, as you say), take a look at this Code Review answer. I have done this in several workbooks of varying level of complexity, and the time for reapplying protection is negligible in all versions I've tried, including 2010.
更多推荐
工作表保护:UserInterFaceOnly不见了
发布评论