Microsoft KB Archive/123327

{|
 * width="100%"|

-

The information in this article applies to:


 * Microsoft Excel for Windows, versions 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 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.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