XL7: Error Using OLE Automation with Microsoft Word 7.0

ID: Q138289

The information in this article applies to:

SYMPTOMS

When you use OLE Automation between Microsoft Excel for Windows 95, version 7.0, and Microsoft Word for Windows 95, version 7.0, to create a mail merge document, you may receive either of the following error messages:

   Run Time Error '51' Microsoft Word--This task is taking longer than
   expected. Do you want to continue waiting?

   (Note that the Continue button is unavailable.)

   -or-

   Microsoft Excel is waiting for another application to complete an
   OLE action

RESOLUTION

To work around this problem open the Microsoft Excel worksheet in Microsoft Word, save it as a Microsoft Word document and use the new Microsoft Word file as your source data. The following macro shows how this can be done programmatically.

Microsoft provides macro 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 macro is provided as is and Microsoft in no way guaranties that the following code can be used in all situations and will not support modifications of the code to suit specific customer requirements.

Sub Create_Mailing_Labels()
Dim Word As Object

  Set Word = CreateObject("word.basic") 'creates the Word object

  With Word
    .AppShow ' Makes Word Visible
    'Sends keystrokes to the Open Worksheet dialog
    SendKeys "{TAB}{TAB}{TAB}{ENTER}"

    'opens a the Microsoft Excel file
    'NOTE: This line needs to be changed to point to the data file
    '(i.e. "c:\data.xls")
    .FileOpen Name:="c:\<path>\<filename>"

    'NOTE: This line needs to be changed to point to a new name for
    'the file (i.e. "c:\data.doc")
    'saves the file as a Microsoft Word document
    .FileSaveAs Name:="c:\<path>\<filename>"

    .FileClose 'closes the file
    .FileNewDefault ' Opens up a new blank document

    'makes the active window a main document
    .MailMergeMainDocumentType 1

    ' opens up the data source
    'NOTE: This line needs to be changed to point to the new file
    '(i.e. "c:\data.doc")
    .MailMergeOpenDataSource Name:="c:\<path>\<filename>", LinkToSource:=0

    'THESE FIELDS WILL BE SPECIFIC TO THE DATA BEING USED
    'Sets up the fields to be used for the mail merge
    .ToolsCreateLabels LabelAutoText:="ToolsCreateLabels3",_
     LabelText:="<<CONTACT>>" + Chr$(13) + "<<ADDRESS>>" + Chr$(13) + _
    "<<CITY>>,  <<REGION>>  <<ZIP_CODE>>  <<COUNTRY>>"

    .MailMergeToDoc 'Merges data records with the main document

    ' saves the active document
    'NOTE: This line needs to be changed to point a new file name
    '(i.e. "c:\result.doc")
    .FileSaveAs Name:="c:\<path>\<filename>"

  End With
  Set word = Nothing 'clears the object variable

End Sub

STATUS

Microsoft has confirmed this to be a problem in the Microsoft products listed at the beginning of this article. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.

Additional query words: 7.00

Keywords          : kbinterop kbole kbprg xlwin 
Version           : 7.00
Platform          : WINDOWS

Last Reviewed: September 3, 1997