XL: WordBasic Command FileExit Generates An Error

Last reviewed: December 1, 1997
Article ID: Q123327
The information in this article applies to:
  • Microsoft Excel for Windows, version 5.0, 5.0c
  • Microsoft Excel for the Macintosh, versions 5.0, 5.0a
  • Microsoft Excel for Windows 95, version 7.0
  • Microsoft Word for Windows, version 6.0
  • Microsoft Word for the Macintosh, version 6.0
  • Microsoft Word for Windows 95, version 7.0

SYMPTOMS

In Microsoft Excel, you will receive the following error message if you use the WordBasic FileExit method in a macro that performs Automation with Microsoft Word:

   Run-time error 545:
   The FileExit statement is currently disabled.

CAUSE

The FileExit method of the WordBasic language cannot be invoked via Automation. Because Automation cannot start a new instance of Word after the initial instance, it assumes that you started Word and you are responsible for exiting the application.

WORKAROUND

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 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.asp

To avoid receiving this error message, use the following code to set the Word object to Nothing rather than using the WordBasic FileExit command:

   Sub WordOLE()
      Dim Word as Object

      ' Create the Word object.
      Set Word=CreateObject("Word.Basic")

      ' Start a new document in Word.
      Word.FileNew

      ' Insert the text "Some Text" on the new document in Word.
      Word.Insert "Some Text"

      ' Clear the Word object.
      Set Word = Nothing

   End Sub

MORE INFORMATION

The CreateObject function will start Word version 6.0 if it is not already running, otherwise it will use the currently-active instance of Word. The Set Word = Nothing statement will exit Word if Word was started by the CreateObject statement.

In Microsoft Word version 6.0 for Macintosh, you can use FileQuit in place of FileExit. If you use the FileQuit command in a macro that performs OLE Automation with Word, you will receive the same results.

You will receive the error message "The FileExit statement is currently disabled" if you use the following code which uses the WordBasic FileExit command:

   Sub WordOLE()
      Dim Word as Object

      ' Create the Word object.
      Set Word=CreateObject("Word.Basic")

      ' Start a new document in Word.
      Word.FileNew

      ' Insert the text "Some Text" on the new document in Word.
      Word.Insert "Some Text"

      ' Attempt to quit Word.
      Word.FileExit

   End Sub

REFERENCES

"Visual Basic User's Guide," pages 189-198

For additional information, please see the following article in the Microsoft Knowledge Base:

   ARTICLE-ID: Q108043
   TITLE     : How VB Can Use OLE Automation with Word Version 6.0


Additional query words: 5.00 6.00
Keywords : kbcode kbinterop kbprg AutoGnrl PgmHowto
Version : WINDOWS:5.0,5.0c,7.0; MACINTOSH:5.0,5.0a
Platform : MACINTOSH WINDOWS
Issue type : kbprb
Solution Type : kbworkaround


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: December 1, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.