Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel 允许用户在图纸锁定时隐藏列_Excel_Vba_Show Hide - Fatal编程技术网

Excel 允许用户在图纸锁定时隐藏列

Excel 允许用户在图纸锁定时隐藏列,excel,vba,show-hide,Excel,Vba,Show Hide,当工作簿中的工作表被锁定时,我使用以下VBA脚本为用户提供某些权限。我不知道如何添加一行,允许用户隐藏和取消隐藏列。有什么建议吗 Sub EnableOutlining() 'Update 20140603 Dim xWs As Worksheet Set xWs = Application.ActiveSheet Dim xPws As String xPws = Application.InputBox("Password:", xTitleId, "", Type:=2) xWs.Prot

当工作簿中的工作表被锁定时,我使用以下VBA脚本为用户提供某些权限。我不知道如何添加一行,允许用户隐藏和取消隐藏列。有什么建议吗

Sub EnableOutlining()
'Update 20140603
Dim xWs As Worksheet
Set xWs = Application.ActiveSheet
Dim xPws As String
xPws = Application.InputBox("Password:", xTitleId, "", Type:=2)
xWs.Protect Password:=xPws, Userinterfaceonly:=True
xWs.EnableOutlining = True
xWs.EnableOutlining = True
xWs.EnableAutoFilter = True
xWs.EnableFormatConditionsCalculation = True
End Sub

正在研究一种方法,以检查最后一个用户操作实际上是隐藏/取消隐藏,而不是其他操作。但现在应该允许用户隐藏/取消隐藏

对于列:

xWs.protect Password:= "1234",AllowFormattingColumns:= true
对于行:

xWs.protect Password:= "1234",AllowFormattingRows:= true
此脚本应帮助将用户活动限制为仅调整列宽。(lastAction将隐藏列描述为调整宽度,必须是隐藏列实际上只是一个最小化列宽的函数,而不是一些特殊操作)

Private子工作表\u selection更改(ByVal目标作为范围)
将最后一个动作设置为字符串
lastAction=Application.commandbar(“标准”).Controls(&Undo”).List(1)
如果最后一个操作是“列宽”,则
Application.EnableEvents=False
应用程序。撤消
MsgBox“请仅隐藏或取消隐藏列”
Application.EnableEvents=True
如果结束
端接头

谢谢,但我不太明白你想做什么。我只想让用户能够使用VBA在锁定的工作簿中隐藏或取消隐藏他们选择的列。不需要在其他工作表中指定列值。对于建议使用“xWs.AllowFormattingColumns:=true”的第一部分,我得到一个错误,说“找不到方法或数据成员”。我认为这是因为AllowFormattingColumns不是EnableOutlineing()函数的一部分。请参见编辑,抱歉造成混淆。这将在现在起作用,但它还允许用户在隐藏/取消隐藏之外进行其他格式更改。我试图想出一种方法来禁止在隐藏/取消隐藏之外进行任何格式更改@AJD我希望今晚能解决这个问题,ty寻求帮助和意见。
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Dim lastAction As String
        lastAction = Application.CommandBars("Standard").Controls("&Undo").List(1)

    If lastAction <> "Column Width" Then
        Application.EnableEvents = False
        Application.Undo
        MsgBox "PLEASE ONLY HIDE OR UNHIDE COLUMNS"
        Application.EnableEvents = True
    End If
End Sub