我已经有一个成功的“自定义保存”宏来保存-就像一个日期戳。我只想有一个消息框,要求运行它时,有人试图手动保存。我基本上需要“是”才能运行宏,“否”才能正常保存,“取消”才能退出sub。
然而,无论何时我file>save或ctrl+s,它只是保存没有提示。
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Dim answer As VbMsgBoxResult
answer = MsgBox("Would you rather Save-As copy with date stamp?", vbYesNoCancel + vbQuestion + vbDefaultButton1, "You are overwriting the document!")
If answer = vbYes Then
Call filesave
ElseIf answer = vbNo Then
ActiveWorkbook.Save
Else
Exit Sub
End If
End Sub发布于 2018-12-17 21:29:54
您需要将子过程的参数中的Cancel设置为True,以便停止当前的保存操作。
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Dim answer As VbMsgBoxResult
answer = msgbox("Would you rather Save-As copy with date stamp?", vbYesNoCancel + vbQuestion + vbDefaultButton1, "You are overwriting the document!")
If answer = vbYes Then
'Cancel the current standard save operation
Cancel = True
Call filesave
ElseIf answer = vbNo Then
'don't do anything; the standard save operation will proceed
Else
'Cancel the current standard save operation
Cancel = True
End If
End Subhttps://stackoverflow.com/questions/53823119
复制相似问题