简体   繁体   English

Workbook_NewSheet(以Shy对象为对象)

[英]Workbook_NewSheet(Byval Sh as Object)

I have implemented 2 different levels of authorized access to ThisWorkbook. 我已经实现了对ThisWorkbook的2种不同级别的授权访问。 Level 1 only allows the user to modified a specific visible worksheet and does not authorize him/her to do anything else, including adding a new worksheet. 级别1仅允许用户修改特定的可见工作表,并且不授权他/她执行任何其他操作,包括添加新工作表。 (And level 2 users are allowed to see everything and do anything to the workbook). (并且2级用户被允许查看所有内容并对工作簿执行任何操作)。

My problem is how to prevent level 1 user from trying to create a new sheet. 我的问题是如何防止1级用户尝试创建新表。 I am attempting to use "Workbook_NewSheet" event to handle this event by immediately deleting this sheet the moment it is created. 我试图通过在创建工作表时立即删除此工作表来使用“ Workbook_NewSheet”事件来处理此事件。 However, the argument "Sh" is passed by value, and as an "Object", not "Worksheet". 但是,参数“ Sh”按值传递,并且作为“对象”而不是“工作表”传递。 I can't modify (or deleting) this "Byval" object. 我无法修改(或删除)此“ Byval”对象。

Anyone has any advice? 有人有什么建议吗?

Thanks, 谢谢,

You can refer to Sh like below. 您可以像下面这样参考Sh The code below turns off alerts, deletes the newly created sheet, and then turns alerts back on. 下面的代码关闭警报,删除新创建的工作表,然后重新打开警报。

Private Sub Workbook_NewSheet(ByVal Sh As Object) Application.DisplayAlerts = False Sh.Delete Application.DisplayAlerts = True End Sub

You can do that by protect the workbook with password 您可以通过使用密码保护工作簿来实现

protecting the structure of a workbook will prevent users from Inserting new worksheets or chart sheets. 保护工作簿的结构将阻止用户插入新的工作表或图表表。 Password protect worksheet or workbook elements 密码保护工作表或工作簿元素

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM