XL: Controlling Alerts and Updating in MS Excel OLE ServerLast reviewed: December 1, 1997Article ID: Q153043 |
The information in this article applies to:
SYMPTOMSWhen Microsoft Excel is being used as an OLE Server during an OLE Automation session, the ScreenUpdating property and the DisplayAlerts property are always set to TRUE. Attempts by the controller application to reset either of these properties to FALSE through code in the controller application ("in-process"), will be ignored.
CAUSEThis happens because, during OLE Automation, each line of code that is sent to Microsoft Excel to be run from an OLE controller is being treated as a separate Microsoft Excel macro. The screen updating or alerts would only be turned off for that one line of code and be turned back on for the next line of code that is sent to Microsoft Excel to be run. Therefore, using the DisplayAlerts property or the ScreenUpdating property in this case is not effective.
RESOLUTIONMicrosoft 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 engineers 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/refguide/default.aspIn order to effectively disable screen updating or displaying alerts in Microsoft Excel while Microsoft Excel is an OLE server in an OLE Automation session, you must either make sure that the calls are made from Microsoft Excel by running a Microsoft Excel macro to perform the tasks or write the code in such a way as to prevent the occurrence in the first place. Workaround 1: Running a Microsoft Excel Macro from an OLE Controller You could use the Run method from the OLE controller to tell Microsoft Excel to run a macro that exists in Microsoft Excel. From this macro you can effectively include DisplayAlerts or ScreenUpdating before the commands in question. If Microsoft Visual Basic version 4.0 is being used as the OLE controller application, you could alternatively place the Visual Basic code that controls Microsoft Excel into an in-process (DLL) OLE Server. The classes provided by the in-process server must be created in a Microsoft Excel macro, not by a Visual Basic program, unless the Visual Basic program is another DLL loaded by Microsoft Excel. For additional information, please see the following article in the Microsoft Knowledge Base:
ARTICLE-ID: Q124494 TITLE : XL5: OLE Automation Example: Running Macro in Visual Basic 3.0Workaround 2: Write Code to Avoid the Behavior You can anticipate what methods may cause a dialog box to appear and write the code to avoid the dialog box. This could also be true for screen updating, but it sometimes can't be avoided. Following are two examples of code using Microsoft Project as the OLE controller application that will avoid prompts for user input. This code could easily be applied to other OLE controller applications that support OLE Automation. The following Visual Basic for Applications macro uses OLE Automation to delete a sheet in a newly created workbook and to save the workbook to the hard drive. It avoids using the Delete method (which produces a warning message) and uses the Move method, instead, to avoid the message.
STATUSThis behavior is by design.
MORE INFORMATIONThere are some tasks in Microsoft Excel that will cause Microsoft Excel to interact with the user. For example, closing a workbook without saving changes will cause Microsoft Excel to ask if the user wants to save changes; deleting a sheet in a workbook will ask if the user is sure he or she wants to delete it; saving a workbook to a name that already exists will ask the user if the user is sure he or she wants to replace it. These prompts may be inappropriate and confusing to the user. These prompts can be disabled in a Visual Basic for Application macro in Microsoft Excel by using the following line of code:
Application.DisplayAlerts = FALSEFor additional information, please see the following article in the Microsoft Knowledge Base:
ARTICLE-ID: Q129153 TITLE : How to Avoid "Save Changes?" When You Close a WorkbookAlso, performing some tasks in Microsoft Excel will cause frequent screen updates in Microsoft Excel and cause the screen to flash. This behavior may also be inappropriate and confusing to the user. This may also slow down Visual Basic for Applications macros that are run in Microsoft Excel. This screen updating can be disabled in a Visual Basic for Application macro in Microsoft Excel by using the following line of code:
Application.ScreenUpdating = FALSEHowever, neither of these properties are effectively set to FALSE when they're being run in a line of code from an OLE controller application (for example, Microsoft Project version 4.1 for Windows 95, Microsoft Project version 4.0 for the Macintosh, Microsoft Word version 7.0 for Windows 95, Microsoft Word version 6.0 for the Macintosh, Microsoft Visual Basic version 4.0 for Windows 95). This is because each line of code is being treated as a separate Microsoft Excel macro when commands are sent to Microsoft Excel through OLE Automation.
REFERENCES"Object Programming with Visual Basic 4," version 4.0, Chapter 9, "Miscellaneous Gotchas: Surprises in Working with Microsoft Excel and Visual Basic" "Using MS Excel as an OLE Automation Object" by Tim Tow, version 5.0, Microsoft Technet CD, April '96, p. 21 For more information about OLE Automation in Microsoft Excel version 7.0, click Answer Wizard on the Help menu and type:
OLE AutomationFor more information about DisplayAlerts in Microsoft Excel version 7.0, click Answer Wizard on the Help menu and type:
DisplayAlertsFor more information about ScreenUpdating in Microsoft Excel version 7.0, click Answer Wizard on the Help menu and type:
ScreenUpdating |
Additional query words: 5.00 5.00a 5.00c 7.00
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |