Using DDE and Macro Substitution with FoxPro and Word

Last reviewed: April 30, 1996
Article ID: Q114492
The information in this article applies to:
  • Microsoft Visual FoxPro for Windows, version 3.0
  • Microsoft FoxPro for Windows, versions 2.5, 2.5a, 2.5b, 2.6

SUMMARY

The following code example shows how to pass a filename stored in a memory variable to Microsoft Word for Windows using dynamic data exchange (DDE) and macro substitution.

MORE INFORMATION

This code stores the desired path and filename to a memory variable called x using the GETFILE() function, starts the DDE link, and opens (using macro substitution) the Word for Windows file whose name is stored in the memory variable x. At this point, the document can be edited in Word. Then the link to Word is terminated, returning control to the client application (FoxPro). This example is useful for selecting and processing a file dynamically using FoxPro for Windows as the client and Word for Windows as the server application.

   *** CALLWORD.PRG ***

   X = GETFILE()                   && Gets file name from user
   RUN /N C:\WINWORD\WINWORD.EXE   && Starts Word

   iCHANNEL= DDEInitiate("WinWord", "System")  && Initiates DDE channel

   * The following command opens the desired document using a generic
   * memory variable called x with macro substitution.
   =DDEExecute(iCHANNEL,'[FileOpen "&X"]')

   =DDETerminate(iCHANNEL)          && Terminates DDE channel

REFERENCES

Word for Window "User's Guide," version 2.0, Chapter 42, "Using Macros" Word for Windows Help file, version 2.0, "WordBasic Programming Language" "Using WordBasic," Microsoft and Wextech Systems, Inc., Chapter 5, "Dynamic Data Exchange"


Additional reference words: VFoxWin 3.00 FoxWin 2.50 2.50a 2.50b 2.60
KBCategory: kbinterop kbprg
KBSubcategory: FxinteropDde


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: April 30, 1996
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.