Excel:打开工作簿时,EnableOutlining似乎默认为False [英] Excel: EnableOutlining seems to default to False on opening workbook
问题描述
与其他许多人一样,我希望能够使用受保护的工作表上的+/-小按钮启用分组和取消分组.每个人似乎都已经成功地使用了保护工作表,启用概述并再次对其取消保护的相同类型的代码,这很好,并且可以正常工作,除非我保存工作表然后再次将其重新打开,EnableOutlining始终设置为False,如果工作表受到保护,我将无法使用+/-按钮.我还应该做一些其他事情来永久保存此设置,而不仅仅是在会话期间吗?
Like many other people, I want to be able to enable grouping and ungrouping with the little +/- buttons on a protected worksheet. Everyone seems to have succeeded with the same sort of code that protects the worksheet, enables outlining and then unprotects it again, which is great and it works except if I save the sheet and then re-open it again EnableOutlining is always set as False, and if the sheet is protected I cannot use the +/- buttons. Is there something else I am supposed to do to save this setting permanently, and not just for the duration of the session?
这是我一直在使用的代码:
Here's the code I have been using:
Private Sub Workbook_Open()
MsgBox ActiveSheet.EnableOutlining
End Sub
Sub EnableOutliningWithProtection_AllSheets()
'PURPOSE: Allow Outline functionality during Protection in all Sheets
'SOURCE: www.TheSpreadsheetGuru.com/the-code-vault
'(Except edited by me to include the Errorcatch)
Dim sht As Worksheet
On Error GoTo Errorcatch
'Loop through each Worksheet in ActiveWorkbook
For Each sht In ActiveWorkbook.Worksheets
'Password Protect Current Sheet
sht.Protect Password:="", UserInterfaceOnly:=True
'Enable Group Collapse/Expand Capabilities
sht.EnableOutlining = True
'Unprotect Sheet
sht.Unprotect ""
Next sht
Exit Sub
Errorcatch:
MsgBox Err.Description
End Sub
(我有Workbook_Open()位来检查EnableOutlining是否仍然为True)我已经看到了保护UserInterfaceOnly和EnableOutlining"的问题,但是我认为由于代码是为C#编写的,因此我认为应用的结果并不适用,而且我也不打算保护UserInterfaceOnly.
(I've got the Workbook_Open() bit to check if EnableOutlining was still True) I've seen the 'protect UserInterfaceOnly and EnableOutlining' question, but I didn't think the results applied as the code was written for C#, and I'm not looking at protecting UserInterfaceOnly.
推荐答案
您不能永久保存它.打开工作簿时,必须使用 Open
事件将其重置.
You can't save it permanently. You have to use the Open
event to reset it when the workbook is opened.
Private Sub Workbook_Open()
EnableOutliningWithProtection_AllSheets
End Sub
这篇关于Excel:打开工作簿时,EnableOutlining似乎默认为False的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!