I have an excel VBA macro which does continuous updates of the database.
I trigger the macro using ActiveX Controls, "Start" button on the excel sheet.
I want to display the status as " Working " in one of the cells of the spreadsheet while it is working properly
In case of some error it should display " Stopped Working ".
How can I do that?
Put this in your button's OnClick method:
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..."
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.