Microsoft KB Archive/169565
Article ID: 169565
Article Last Modified on 1/25/2005
- Microsoft Visual FoxPro 3.0 Standard Edition
- Microsoft Visual FoxPro 3.0b Standard Edition
- Microsoft Visual FoxPro 5.0 Standard Edition
- Microsoft Visual FoxPro 5.0a
This article was previously published under Q169565
When using OLE automation to interact with Microsoft Word 97 and the Visual Basic for Applications language, certain commands return the following error to Visual FoxPro:
This problem is caused by a problem in the way Word 97 returns mismatched errors from the OLE DISPATCH methods.
To resolve this problem, use one of the following methods:
- Use the equivalent Word.Basic methods with the WordBasic property within the Word.Application object. See the example below.
- Use only the Word.Basic object.
Microsoft has confirmed that this is a bug in the Microsoft products that are listed in the "Applies to" section. This bug was corrected in Visual Studio 97 Service Pack 2. For additional information about Visual Studio 97 Service Pack 2, click the following article number to view the article in the Microsoft Knowledge Base:
170365 Visual Studio 97 service packs - what, where, and why
Starting with Word 97, OLE automation from other applications, such as Visual FoxPro, can access the Word 97 Visual Basic for Applications (VBA) objects by issuing the CreateObject("Word.Application") command in Visual FoxPro. However, some of the methods used in Word 97 VBA return errors back to the client application. When an error is returned to the client application, like Visual FoxPro, it may be necessary to use older Word Basic statements and functions in conjunction with the newer Word.Application methods and properties. The purpose of the WordBasic property is to return an Automation object (Word.Basic) that includes methods for all the WordBasic statements and functions available in Word version 6.0 and Word for Windows 95.
To accomplish this while there is reference created to the Word.Application object, preface the Word.Basic statement or function with the WordBasic property, then follow with the desired Word.Basic statement or function. See the code example below.
The ActiveDocument.SaveAs method is not the only method that returns the above error, it is the only one covered in this article. Again if the error is returned, try using one of the covered workarounds.
Steps to reproduce behavior
The following code can be entered in the Command window, in a program, or in a method on a form:
oWord=CreateObject("Word.Application") oWord.Documents.Add oWord.Selection.InsertAfter("This is a test") oWord.Visible=.T. *The line below will error. But this is a valid Word VBA command oWord.ActiveDocument.SaveAs("Mydoc") oWord.Quit
To avoid the above error, revert back to the WordBasic equivalent command. Replace the ActiveDocument.SaveAs above with the following line:
oWord.WordBasic.FileSaveAs("Mydoc") && Will save document
Another option is to use only the Word.Basic object model. Enter the following code in the Command window, in a program, or in a method on a form:
oWord=CreateObject("Word.Basic") oWord.FileNew oWord.Insert("This is a test") oWord.AppShow oWord.FileSaveAs("Mydoc") oWord.FileQuit
Microsoft Word for Windows 97 on-line help. Visual Basic for Applications help that shipped with Word for Windows version 97. For additional information, click the following article number to view the article in the Microsoft Knowledge Base:
169547 Some OLE automation commands fail with Visual Fox Pro 5.x
(c) Microsoft Corporation 1997, All Rights Reserved. Contributions by Dean Christopher, Microsoft Corporation
Keywords: kberrmsg kbfix kbvs97sp1fix kbvs97sp2fix kbprb KB169565