Microsoft KB Archive/177000

= MacXL: Run-Time Error When Using DDEInitiate with Word =

Article ID: 177000

Article Last Modified on 1/22/2007

-

APPLIES TO


 * Microsoft Excel 2001 for Mac
 * Microsoft Excel 98 for Macintosh

-



This article was previously published under Q177000



SYMPTOMS
When you run a Microsoft Visual Basic for Applications macro that uses the DDEInitiate command to start Microsoft Word, you may receive the following error message:

Run-time error '-2147352571 (80020005)':

Cannot find data source.



WORKAROUND
Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to 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 requirements.

If you want to programmatically control Word from Excel with a Visual Basic macro, use Automation instead of dynamic data exchange (DDE). The following example for Excel 98 illustrates how to use Automation to start Word and print a file in Word from an Excel macro.  Create a new file in Word. Save the file to the hard disk, and name the file Automation . Quit Word. Start Excel. Start the Visual Basic Editor (press OPTION+F11). On the Insert menu, click Module. On the Tools menu, click References. Click to select the "Microsoft Word 8.0 Object Library" check box, and then click OK.  Type the following code into the module sheet: Sub Automation_to_Word

Dim WordDoc as Word.Application

' Start Word. Set WordDoc = CreateObject("Word.Application.8")

' Open the document that was created in Step 1. You must supply ' the correct path to the document for the FileName argument. WordDoc.Documents.Open FileName:="Mac HD:Automation"

' Print the document. WordDoc.application.PrintOut Range:=wdPrintAllDocument, _ Item:=wdPrintDocumentContent, _ Copies:=1, PageType:=wdPrintAllPages

' Close the document. WordDoc.Documents("Automation").Close

' Quit Word. WordDoc.Quit

' Release the memory used by the variable. Set WordDoc = Nothing

End Sub </li> Run the macro.</li></ol>

The macro starts Word, opens the document that you created in step 1, prints the document, and then quits Word.

<div class="status_section">

STATUS
Microsoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article.

<div class="references_section">