如何在excel表单上显示vbamacros的状态?

我有一个Excel VBAmacros,它不断更新数据库。

我使用ActiveX控件触发macros,在Excel表单上的“开始”button。

我想在工作正常的时候在电子表格的其中一个单元格中显示“正在工作 ”的状态

如果出现错误,应显示“ 停止工作 ”。

我怎样才能做到这一点?

把它放在你的button的OnClick方法中:

Public Sub CommandButton1_Click() On Error GoTo ErrorHandler Dim msgRange As Range ' change this to the cell you want to update Set msgRange = ThisWorkbook.Sheets("Sheet1").Range("A1") msgRange.Value = "Working" ' your code goes here msgRange.Value = "Completed" Set msgRange = Nothing Exit Sub ErrorHandler: msgRange.Value = "Stopped working: " & Err.Description Set msgRange = Nothing End Sub 

或者你可以使用Application.StatusBar这是通常的显示更新的方法: Application.StatusBar = "Updating..."