vba 如何在 Excel 共享工作簿中禁用排序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18548279/
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
How to disable sorting in an Excel shared workbook
提问by Carlos Mu?iz
I would like to allow only the owner of a shared excel workbook to be able to sort data on the file. Whats the best way to do this?
我想只允许共享 excel 工作簿的所有者能够对文件中的数据进行排序。什么是最好的方法来做到这一点?
回答by datatoo
If the main reason for this is not robust security, but the accidental resort that happens in a workbook shared with others this should work in the Worksheet_Activate event
如果这样做的主要原因不是强大的安全性,而是与其他人共享的工作簿中发生的意外手段,这应该在 Worksheet_Activate 事件中起作用
This is not even attempting to hide the sorting prohibition
这甚至不是试图隐藏排序禁令
Private Sub Worksheet_Activate()
Dim WhoCanSort As String
WhoCanSort = ThisWorkbook.WriteReservedBy
If WhoCanSort = "Charlie" Then
ActiveSheet.Unprotect
Else:
ActiveSheet.Protect AllowSorting:=False
End If
End Sub
回答by Aviva M.
There is another approach that doesn't require a macro. If you use the "Allow Users to Edit Ranges" feature, you can keep the cells locked and the worksheet protected for most users, but define ranges of cells that can be edited by a particular user. See this article: http://blog.softartisans.com/2013/10/01/kb-sorting-locked-cells-in-protected-worksheets/
还有另一种不需要宏的方法。如果您使用“允许用户编辑范围”功能,您可以为大多数用户锁定单元格并保护工作表,但定义可由特定用户编辑的单元格范围。请参阅这篇文章:http: //blog.softartisans.com/2013/10/01/kb-sorting-locked-cells-in-protected-worksheets/