OL97: Problems Automating Microsoft Word from VBScript

Last reviewed: March 2, 1998
Article ID: Q174469
The information in this article applies to:
  • Microsoft Outlook 97
  • Microsoft Word 97 for Windows
  • Microsoft Word for Windows 95, versions 7.0, 7.0a

SYMPTOMS

When automating Microsoft Word from a custom Microsoft Outlook 97 form using Visual Basic Scripting Edition (VBScript), you receive any of the three following errors:

Using the Word.Basic object with Microsoft Word 95:

   Operation failed.

Using the Word.Basic object with Microsoft Word 97:

   Object doesn't support this property or method.

Using the Word.Application object:

   Type Mismatch.

CAUSE

These problems are specific to what versions of VBScript and Microsoft Word you are using.

WORKAROUND

If you are using the Word.Basic object with Microsoft Word 95, either:

  • Upgrade to Word 97 and use the Word.Application object (Word 97's native "VBA-based" object model),

    -or-

  • Use a different method of controlling Word 95. One such alternate method might be to create a Visual Basic 5.0 ActiveX component, automate the component from the Outlook form, and have the component automate Word.

If you are experiencing Type Mismatch errors using the Word.Application object from Word 97, upgrade to the Service Release 1 (SR-1) version of Microsoft Office 97 or Microsoft Word 97.

For more information about obtaining the Service Release 1 version of Office 97, please see the following articles in the Microsoft Knowledge Base:

   Article-ID: Q172475
   Title     : OFF97: How to Obtain and Install MS Office 97 SR-1

   Article-ID: Q172527
   Title     : WD97: How to Obtain Word 97 for Windows, Service Release 1

STATUS

Microsoft is researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.

MORE INFORMATION

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

Using the Word.Basic Object

The following VBScript automation code illustrates the problem using the Word.Basic object.

   VBScript Code                                           Status
   --------------------------------------------------------------
   Set Word = Item.Application.CreateObject("Word.Basic")  'OK
   Word.FileNewDefault                                     'OK
   Word.FileOpen "C:\test.doc"                             'OK
   Word.AppShow                                            'Error
   Word.EditGoTo "test"                                    'Error
   Word.Insert "test"                                      'Error
   Word.InsertPara                                         'Error
   Word.InsertDateTime                                     'OK
   Word.FileExit                                           'Error

If you receive the "Object doesn't support this property or method" error, first make sure the error is actually related to this general problem. This is a common error and typically occurs if you mistype or use an incorrect object name. For example, if you type ActiveDocument.Select instead of ActiveDocument.Selection.

Using the Word.Application Object

The following VBScript automation code illustrates the problem using the Word.Application object.

   VBScript Code                                                 Status
   -----------------------------------------------------------------------
   Set Word = Item.Application.CreateObject("Word.Application")  'OK
   Word.Visible = True                                           'OK
   Word.Documents.Add                                            'OK
   Word.Selection.TypeText "This is a test and will error."      'Error

Problems with the Word.Application object are specific to using VBScript version 3.0 and Word 97 (without the SR-1 update).

Summary of Problems

   VBScript   Word.Basic   Word.Basic   Word.Application   Word.Application
   version    in Word 95   in Word 97   in Word 97         in Word 97 SR-1
   ------------------------------------------------------------------------
   1.0        Errors       Errors       OK                 OK

   2.0        Errors       Errors       OK                 OK

   3.0        OK           OK           Errors             OK

REFERENCES

For more information about creating solutions with Microsoft Outlook 97, please see the following articles in the Microsoft Knowledge Base:

   Article-ID: Q166368
   Title     : OL97: How to Get Help Programming with Outlook

   Article-ID: Q170783
   Title     : OL97: Q&A: Questions about Customizing or
               Programming Outlook

For more information about automating Microsoft Word 95, please see the following article in the Microsoft Knowledge Base:

   Article-ID: Q161547
   Title     : How to Use OLE Automation with Word 6.0/7.0


Additional query words: OutSol OutSol97
Version : WINDOWS:97
Platform : WINDOWS
Issue type : kbbug
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: March 2, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.