vba 保护形状,以便用户可以修改但不能删除

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17443568/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 22:02:32  来源:igfitidea点击:

Protect shapes so users can modify but not delete

excelvbashapesprotection

提问by mcallagain

I have a workbook with some shapes that I don't want users to delete easily. They are linked with an index, and the index number is linked with a whole other bunch of stuff.

我有一个工作簿,其中包含一些我不希望用户轻松删除的形状。它们与索引相关联,而索引号与其他一堆东西相关联。

However, the user needs to move the shapes around and resize them.

但是,用户需要四处移动形状并调整它们的大小。

How can I set the protection on the sheet to allow users to modify the shapes but not delete them?

如何在工作表上设置保护以允许用户修改形状但不能删除它们?

The ability to do this in VBA would be useful too, as a few of my macros unprotect and then protect cells.

在 VBA 中执行此操作的能力也很有用,因为我的一些宏取消保护然后保护单元格。

回答by Archlight

This is not possible.

这不可能。

You can lock all shapes in the workbook by using this code

您可以使用此代码锁定工作簿中的所有形状

Private Sub Workbook_Open()
  ActiveSheet.Protect Password:="test", userinterfaceonly:=True
  Dim shape As shape
  For Each shape In ActiveSheet.Shapes
    shape.Locked = True
  Next
End Sub

or you build a plugin for Excel in dot.net. This blog describes how you would do that for shapes and there you can use events to overide the delete.

或者您在 dot.net 中为 Excel 构建一个插件。该博客描述了如何对形状执行此操作,并且您可以使用事件来覆盖删除。

create excel events for shapesor Microsoft excel shape events

为形状Microsoft excel 形状事件创建 excel事件