保存数据时如何弹出“成功保存数据”消息?

时间:2019-06-09 13:14:30

标签: excel vba

我当前是第一次使用Excel VBA,并且已经设法创建了可以从中输入数据的用户表格。我目前正在寻找一个代码,该代码在成功保存数据后会弹出,提示“数据已成功保存”或“错误!数据未保存”。我怎样才能做到这一点? 这是我到目前为止所拥有的

Private Sub cmdAddData_Click()
If ComboBox1.Value = "" Then
    MsgBox "You must select your full name", vbCritical
    Exit Sub
End If
If ComboBox2.Value = "" Then
    MsgBox "You must select the full name of your 1st nominee", vbCritical
    Exit Sub
End If
If ComboBox3.Value = "" Then
     MsgBox "You must select the readiness level of your 1st nominee", vbCritical
    Exit Sub
End If

Dim wks As Worksheet
Dim AddNew As Range
Set wks = Sheet6
Set AddNew = wks.Range("A65356").End(xlUp).Offset(1, 0)

AddNew.Offset(0, 0).Value = ComboBox1.Value
AddNew.Offset(0, 8).Value = ComboBox2.Value
AddNew.Offset(0, 18).Value = ComboBox3.Value

1 个答案:

答案 0 :(得分:1)

一种简单的方法:

Sub qwerty()
    s = Application.InputBox(Prompt:="enter a value", Type:=1)
    [A1] = s
    On Error GoTo issuewarning
    ActiveWorkbook.Save
    MsgBox "data has been saved successfully"
    Exit Sub
issuewarning:
     MsgBox "error! data not saved"
     Exit Sub
End Sub