我有一个从WorkbookOpen事件中调用的例程 - 它所做的只是隐藏/取消隐藏适当的工作表并保护其中一些(我将下面的代码放入),这会导致一个奇怪的问题是屏幕上的电子表格的图片,但是我选择单元格,更改值等等的任何内容都发生在工作表上,但没有显示在屏幕上 - 底部也看不到工作表标签。
如果我单击关闭按钮然后取消,在询问我是否要保存的框中...我的所有更改都在那里,工作表标签可见,Excel正常工作(没有WorkbookBeforeSave例程,所以没有触发代码)
我很想知道造成这种情况的原因(甚至是解决方法),因为它让我疯狂。
Open事件调用的代码是:
Sub ProtectAndHide()
Dim xSheet As Worksheet
Application.ScreenUpdating = False
For Each xSheet In ThisWorkbook.Worksheets
Select Case UCase(xSheet.Codename)
Case "PROPERTIES", "COA", "ASSUMPTIONS", "ENGINE", "EXECSUMM", "NOTES", "DISCLAIMER", "COVER"
xSheet.Visible = xlSheetVisible
xSheet.Protect Password:=HIDDEN.Range("iWord")
Case "COAMAP", "SLDEPN"
xSheet.Visible = xlSheetHidden
xSheet.Protect Password:=HIDDEN.Range("iWord")
Case "HIDDEN", "REPSHEET", "CONTENTSSHEET", "ACTIONS"
xSheet.Visible = xlSheetVeryHidden
End Select
Next xSheet
End Sub
答案 0 :(得分:2)
最后添加Application.ScreenUpdating = True
。
Sub ProtectAndHide()
Dim xSheet As Worksheet
Application.ScreenUpdating = False
For Each xSheet In ThisWorkbook.Worksheets
Select Case UCase(xSheet.Codename)
Case "PROPERTIES", "COA", "ASSUMPTIONS", "ENGINE", "EXECSUMM", "NOTES", "DISCLAIMER", "COVER"
xSheet.Visible = xlSheetVisible
xSheet.Protect Password:=HIDDEN.Range("iWord")
Case "COAMAP", "SLDEPN"
xSheet.Visible = xlSheetHidden
xSheet.Protect Password:=HIDDEN.Range("iWord")
Case "HIDDEN", "REPSHEET", "CONTENTSSHEET", "ACTIONS"
xSheet.Visible = xlSheetVeryHidden
End Select
Next xSheet
Application.ScreenUpdating = True
End Sub