XL97: Excel Hangs When You Programmatically Save a WorkbookID: Q143452
|
When you save a workbook in Microsoft Excel 97, the program may appear to
stop responding (hang), and the following symptoms may occur:
This problem occurs when all of the following conditions are true:
ActiveWorkbook.OnSave = "<Macro name>"
where <Macro name> is the name of a macro.
Application.ScreenUpdating = False
-and-
To prevent this problem from occurring, add the following code to all macros that you specify in the OnSave command:
Application.ScreenUpdating = True
before the end of each macro.
Microsoft has confirmed this to be a problem in the Microsoft products listed at the beginning of this article.
Microsoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs. If you have limited programming experience, you may want to contact the Microsoft fee-based consulting line at (800) 936-5200. For more information about the support options available from Microsoft, please see the following page on the World Wide Web:
http://www.microsoft.com/support/supportnet/overview/overview.aspIn Microsoft Excel 7.0 and Microsoft Excel 97, you can use the OnSave property to specify a macro that runs after you initiate saving a workbook, and before Microsoft Excel saves the workbook.
Sub SetOnSaveTrigger()
ActiveWorkbook.OnSave = "WorkbookSaving"
End Sub
Sub WorkbookSaving(Arg As Boolean)
Application.ScreenUpdating = False
MsgBox "Now saving file!"
End Sub
After you run the first macro, Microsoft Excel automatically runs the
second macro each time you save the active workbook.
Application.ScreenUpdating = False
You can enable screen updating by setting the ScreenUpdating property to
True. Usually, this step is not necessary: Microsoft Excel automatically
enables screen updating when the macro stops running. However, there is one
exception to this rule. If a macro that is run by the OnSave property
contains a command to turn off screen updating, Microsoft Excel does not
enable screen updating automatically when the macro is finished.
Sub WorkbookSaving(Arg As Boolean)
Application.ScreenUpdating = False
MsgBox "Now saving file!"
Application.ScreenUpdating = True
End Sub
Additional query words: XL97 hung freeze frozen locked stopped
Keywords : kbprg kbdta kbdtacode xlloadsave KbVBA xlvbmigrate
Version : WINDOWS:
Platform : WINDOWS
Issue type : kbbug
Last Reviewed: July 1, 1999