Microsoft KB Archive/138289

= Error Using OLE Automation with Microsoft Word 7.0 =

Article ID: 138289

Article Last Modified on 10/11/2006

-

APPLIES TO


 * Microsoft Excel 95 Standard Edition
 * Microsoft Word 95 Standard Edition

-



This article was previously published under Q138289





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:\ \ "

'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:\ \ "

.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:\ \ ", 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:="<>" + Chr$(13) + "<>" + Chr$(13) + _ "<>, <>  <>  <>"

.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:\ \ "

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: XL7

Keywords: kbinterop kbprogramming KB138289

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.