Using DDE and Macro Substitution with FoxPro and Word

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 query words: VFoxWin FoxWin 2.50 kbvfp300


Keywords          : FxinteropDde 
Version           : 2.50 2.50a 2.50b 2.60 3.00
Platform          : WINDOWS 
Issue type        : 


Last Reviewed: August 23, 1999
© 1999 Microsoft Corporation. All rights reserved. Terms of Use.