我正在寻找一种安全地组合所有这些代码的方法。问题是必须避免重复的 BeforeClose 名称。我有点困惑如何解决这个问题。
//全屏
Private Sub Workbook_Open()
Application.DisplayFullScreen = True
Application.CommandBars("Full Screen").Visible = False
End Sub
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Application.DisplayFullScreen = False
Application.CommandBars("Full Screen").Visible = True
End Sub
//公式栏
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Application.DisplayFormulaBar = True
End Sub
Private Sub Workbook_Open()
Application.DisplayFormulaBar = False
End Sub
//标题
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Application.DisplayHeadings = True
End Sub
Private Sub Workbook_Open()
Application.DisplayHeadings = False
End Sub
//拖放
Private Sub Workbook_AfterSave(ByVal Success As Boolean)
chgflag = "Y"
End Sub
Private Sub Workbook_BeforeClose(Cancel As Boolean)
If chgflag <> "Y" Then
MsgBox ("You are Closing this before Generating Your Target Docs")
End If
Application.CellDragAndDrop = True
End Sub
Private Sub Workbook_Open()
Application.CellDragAndDrop = False
End Sub
非常感谢您的想法。
答案1
Workbook_Open
或是触发器Workbook_BeforeClose(Cancel As Boolean)
,用于在给定时间执行您想要的命令。因此,将所有命令放在Private Sub
andEnd Sub
语句之间。例如;
Private Sub Workbook_Open()
Application.DisplayFullScreen = True
Application.CommandBars("Full Screen").Visible = False
Application.DisplayFormulaBar = False
Application.DisplayHeadings = False
Application.CellDragAndDrop = False
End Sub
对事件也采取同样的措施BeforeClose
。