Protecting and Hiding Columns same as “Very Hidden” Sheets

谁说胖子不能爱 提交于 2021-02-10 05:00:52

问题


I am trying to hide some columns and prevent the user to have any access to them; while they can edit other parts of the sheet.

What I am seeking is something like:

ActiveWorkbook.Sheets("Name").Visible = xlSheetVeryHidden 

So user cannot see them. I am aware that one option is adding another sheet and move those columns to there and hide that one sheet; but as I am working on a relatively large data-set and it has a standard format within the company, I prefer not to do so.

I already tried locking the columns and protecting the sheets and checking all the boxes except the ones for selecting locked cells, inserting and deleting both rows and columns (code below).

Function VeryHideColumn(myColumn As Range)

    myColumn.Locked = True
    myColumn.FormulaHidden = True
    myColumn.Hidden = True
    'myColumn.Hidden = xlVeryHidden 'I already tried this

    ActiveSheet.Protect DrawingObjects:=False, Contents:=True, Scenarios:= _
        False, AllowFormattingCells:=True, AllowFormattingColumns:=True, _
        AllowFormattingRows:=True, AllowInsertingHyperlinks:=True, AllowSorting:= _
        True, AllowFiltering:=True, AllowUsingPivotTables:=True
    ActiveSheet.EnableSelection = xlUnlockedCells

End Function

This is the problem: users still can select a range containing these hidden and locked columns and unhide them. Is there any method or trick like VeryHidden for sheets available for ranges?


回答1:


Original Answer:

If the users don't need to format the columns and rows, then there's a work around for this:

If AllowFormattingColumns and AllowFormattingRows were false (which is default if not stated), then user would not be able to hide or unhide them.

Update:

Function below "very hides" only the columns based on above idea;

Function VeryHideColumn(myColumn As Range)
'By M--, April 2017

    myColumn.Locked = True
    myColumn.Hidden = xlVeryHidden
    myColumn.FormulaHidden = True

    ActiveSheet.Protect DrawingObjects:=False, Contents:=True, Scenarios:= _
        False, AllowFormattingCells:=True, AllowFormattingRows:=True, _
        AllowInsertingHyperlinks:=True, AllowSorting:=True, AllowFiltering:=True _
    , AllowUsingPivotTables:=True

End Function

If you want to very hide the rows, then set the AllowFormattingRows to false.



来源:https://stackoverflow.com/questions/43686154/protecting-and-hiding-columns-same-as-very-hidden-sheets

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!