13.2. Displaying Status Bar Messages in Word and Excel

Word and Excel let you display information on the status bar, giving you an easy way to tell the user what's happening in a procedure without halting execution of the code. By displaying status information on the status bar as the procedure works, you can indicate to the user not only what the procedure is doing but also that it's still, in fact, running.

How to Avoid Alarming the User

A problem you'll sometimes encounter is that the user thinks the procedure has frozen, crashed, or failed to work because no changes are visible on screen, whereas in fact your procedure is working properly in the background. If you have a procedure that takes a long time to execute, an update on the status bar lets the user see that the procedure is still working.


The main disadvantage of displaying messages on the status bar is that users may miss them if they're not paying attention or if they're not expecting to see messages there. If the application in question uses the status bar extensively to give the user information (as Word and Excel do), this shouldn't be a problem. But if there's any doubt, notify the user that information will be displayed on the status bar. For example, you might display a message box at the beginning of a procedure to tell the user to watch the status bar for updates.

To display a message on the status bar in Word or Excel, you set the StatusBar property of the Application object to an appropriate string of text. The following example displays the status bar information shown in Figure 13.1:

Application.StatusBar = "Word is formatting the report. Please wait..."

Figure 13.1. In some applications, you can display information on the status bar.

Typically, any information you display on the status bar remains displayed there until you change it or until the application displays a message there itself. For example, if you display a message on the status bar and then invoke the Copy command in Excel, Excel displays its normal Copy message, Select destination and press ENTER or choose Paste, on the status bar, wiping out your message. Application messages trump user-created messages.

If you display a message on the status bar in the course of a procedure, you should update it later in the procedure to avoid leaving a misleading message on the status bar after the procedure has finished running. For example, you might display another message saying that the procedure has finished or clear the status bar by displaying a blank string on it.

To clear the status bar, assign an empty string to it, as in the following statement:

Application.StatusBar = ""

To see the effect of this statement, run it from the Visual Basic Editor with the Word or Excel window (or at least its status bar) visible. You'll see the effect best if you run a statement that displays information on the status bar (such as Application.StatusBar = "Hello, World!") first so that the status bar has information for the Application.StatusBar = "" statement to clear:

Application.StatusBar = "Hello, World!"
Application.StatusBar = ""

Progress Indicators Can Be Written Various Ways

It's especially helpful to display a progress indicator on the status bar during longer processes so that the user can tell that they're still running and that they're making progress. For example, you might display a readout of the progress, such as "Excel is working on sheet 9 out of 150." Even more simply, adding increasing numbers of periods to the end of the status message gives an indication of progress, although it doesn't give an idea of how much longer the task will take.


..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.128.26.141