StatusBar Freeze-Up
2005-12-27
If your VBA code is making a lot of changes to an MS Word document, and at the same time you are attempting to provide status messages to the user via the StatusBar, you will find that eventually MS Word queues up too many screen refresh events and then the status bar stops updating (and the MS Word window also stops refreshing). To solve this problem, turn off screen refreshing while your VBA is applying its updates to the document; then re-enable refreshing once the updating is complete. The only caveat is that you need to be sure to re-enable screen refreshes if a VBA error is encountered.
This problem---of the StatusBar freezing up---is one that I struggled with for a couple of years before stumbling upon this work-around. Searching the 'net for a solution didn't help, this problem is not discussed on any website or USENET newsgroup I have access to (as of 2005-12-27).
The following code snipped demonstrates how to apply this workaround:
Option Explicit
''''
'' Author: Christopher Rath (http://www.rath.ca/Misc/VBA/)
'' Date: 2005-12-27
''
'' ©2005 Christopher Rath. Permission is granted for any use of this
'' code by others as long as this copyright statement is retained,
'' other due and proper credit is provided to the author (e.g., don't
'' claim you wrote this code), and the LGPL license is respected.
''
'' This code is free software; you can redistribute it and/or modify it
'' under the terms of the GNU Lesser General Public License as published
'' by the Free Software Foundation; either version 2.1 of the License.
'' See the LGPL license at http://www.gnu.org/copyleft/lesser.html.
''
'' This package is distributed in the hope that it will be useful, but
'' WITHOUT ANY WARRANTY; without even the implied warranty of
'' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE; on an “AS IS,”
'' “WHERE IS” and “WITH ALL FAULTS” basis.
''
'' Change Log:
'' 2005-12-27 -- Initial release.
''''
Sub test()
' Use "On Error" to ensure that if an error is encountered that we
' go somewhere in the code to re-enable screen refreshing activities.
On Error GoTo CleanUp
' This is the statement that disables screen refreshing.
Application.ScreenUpdating = False
'*** In this section put your VBA that updates the document and ***
'*** posts status messages to StatusBar. ***
Application.StatusBar = "some status message"
CleanUp:
Application.ScreenUpdating = True
End Sub
Note, the sample code is Copyright ©2005 Christopher Rath. Permission is granted for any use of this sample code by others as long as this copyright statement is retained, other due and proper credit is provided to the author (e.g., don't claim you wrote this template), and the LGPL license is respected. This package is free software; you can redistribute it and/or modify it under the terms of version 2.1 of the GNU Lesser General Public License as published by the Free Software Foundation. See the LGPL licenese on the GNU.org website. This package is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE; on an “AS IS,” “WHERE IS” and “WITH ALL FAULTS” basis.