DOCUMENT:Q121957  08-NOV-1994  [FOXPRO]
TITLE   :INF: DDE Macro Example with Excel as Client & FoxPro as Server
PRODUCT :Microsoft FoxPro
PROD/VER:2.5x 2.60 2.60a
OPER/SYS:WINDOWS
KEYWORDS:kbinterop kbprg kbcode kbmacro

--------------------------------------------------------------------
The information in this article applies to:

 - Microsoft FoxPro for Windows, versions 2.5x, 2.6, 2.6a
--------------------------------------------------------------------

SUMMARY
=======

FoxPro for Windows can be used as a dynamic data exchange (DDE) server if
DDEDATA.APP is run before the DDE link is established from Microsoft Excel.
DDEDATA.APP, which is included with FoxPro for Windows, sets up FoxPro as a
DDE server.

Connecting to FoxPro as a DDE server is a little different than connecting
to other DDE servers from Microsoft Excel. See below for an example of
Microsoft Excel Visual Basic for Applications (VBA) macro code used to make
the connection to FoxPro.

MORE INFORMATION
=================

Set Up FoxPro as a DDE Server
-----------------------------

To set up FoxPro as a server, perform the following:

1. Using Project Manager, open the DDEDATA.PJX file located in the
   <FoxPro_directory>\SAMPLE\DDE subdirectory.

2. Build the application, using the default name DDEDATA.APP.

3. Run DDEDATA.APP.

Connect to FoxPro from Excel Using VBA
--------------------------------------

WARNING: ANY USE BY YOU OF THE CODE PROVIDED IN THIS ARTICLE IS AT YOUR OWN
RISK. Microsoft provides this code "as is" without warranty of any kind,
either express or implied, including but not limited to the implied
warranties of merchantability and/or fitness for a particular purpose.

In Microsoft Excel, type the following lines of code in a VBA module sheet
in a workbook:

   Sub foxddetest()

     ChannelNumber = Application.DDEInitiate _
   ("ddedata","c:\fpw26\tutorial\;table invoices")

     returnList = Application.DDERequest(ChannelNumber, "firstrow")

     For i = LBound(returnList) To UBound(returnList)
       Cells(2, i).Formula = returnList(i)
     Next i

     Application.DDETerminate ChannelNumber

   End Sub

The DDEInitiate() command opens a channel to FoxPro. The first argument,
the application or service name, is "ddedata" because DDEDATA.APP is
running in FoxPro. The second argument, the topic, is the path to the
database table, followed by a semicolon, and then the table name. The
variable ChannelNumber contains a numeric value that represents the DDE
channel link.

The DDERequest() command's first argument is the channel number (or its
variable). The second argument is the requested item. Items that can be
requested include: ALL, DATA, FIELDCOUNT, FIELDNAMES, FIRSTROW, LASTROW,
NEXTROW, and PREVROW. Other topics can be programmed within FoxPro
beforehand. This example requests the information from the first row of the
database, which is returned to Microsoft Excel in an array.

The For ... Next loop retrieves the information and places it in the active
sheet of the workbook. This macro should be run from a worksheet, not the
module sheet, through the Tools and Macros menu options.

REFERENCES
==========

FoxPro for Windows "Developer's Guide," version 2.5, pages D12-12 to D12-20

Microsoft Excel "Visual Basic User's Guide," version 5.0, pages 209-217

Additional reference words: FoxWin 2.50 2.50a 2.50b 2.60 2.60a
KBCategory: kbinterop kbprg kbcode kbmacro
KBSubcategory:

=============================================================================

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.

Copyright Microsoft Corporation 1994.