试图在Excel 2007中阻止SAVEAS,取消= True函数不起作用

时间:2015-09-16 01:04:08

标签: excel vba excel-vba

我一直在尝试使用此VBA代码来阻止ThisWorkBook中的SAVEAS功能:

Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
If (SaveAsUI = True) Then
    MsgBox "here"
    Cancel = SaveAsUI
End If
End Sub

我甚至收到了消息" here"但程序很高兴让我使用SaveAs功能。

我有什么遗失的吗?

1 个答案:

答案 0 :(得分:0)

您的代码有效,只需确保您的代码位于ThisWorkbook

enter image description here

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
    If (SaveAsUI = True) Then
        Cancel = SaveAsUI
    End If
End Sub