我需要在Excel中禁用保存选项,但我仍然需要另存为选项才能正常工作...所以我知道如何通过此VBA禁用这两个选项:
Private Sub Workbook_BeforeSave(ByVal SaveUI As Boolean, Cancel As Boolean)
MsgBox "You can't save this workbook!"
Cancel = True
End Sub
但是如何禁用保存却可以让我们保持工作状态。 谢谢你的帮助
答案 0 :(得分:1)
尝试:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
If SaveAsUI = False Then
MsgBox "You can't save this workbook!"
Cancel = True
End If
End Sub
修改强>:
要从ThisWorkbook
类模块删除代码(删除所有内容),我们可以使用此代码:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
If SaveAsUI = False Then
MsgBox "You can't save this workbook!"
Cancel = True
Else
With ThisWorkbook.VBProject.VBComponents("ThisWorkbook").CodeModule
.DeleteLines 1, .CountOfLines
End With
End If
End Sub
注:
ThisWorkbook
课程模块中的所有内容,而不仅仅是Workbook_BeforeSave