PRB: DDERequest() from MS Excel Returns Extra Characters

ID: Q97164

The information in this article applies to:

SUMMARY

The DDERequest() function can be used to return data from a cell in a Microsoft Excel file. (See below for an example.)

The contents of the cell are returned as a text string that is terminated by the ASCII characters 10 and 13 (carriage return and linefeed.) To obtain the desired result, you may need to use FoxPro commands to manipulate these strings.

MORE INFORMATION

1. Start Microsoft Excel. By default, it starts with Sheet1.

2. In cell A1 of Sheet1, type "1" (without the quotation marks) and

   press ENTER.

3. Open the Debug window in FoxPro and type "x" (without the quotation
   marks).

4. In the Command window, issue the following commands:

      chan = DDEInitiate("Excel","Sheet1")
      x = DDERequest(chan,"R1C1")
      =DDETerminate(chan)

In the Debug window, the variable x appears as a character string containing "1" followed by two symbols. These symbols are ASCII characters 13 and 10, representing a carriage return and linefeed, respectively.

To remove these extra characters, use the following command:

  x=left(x,len(x)-2)

The variable x now contains the contents of the Microsoft Excel cell without the extra characters.

Additional reference words: FoxWin 2.50 2.50a DDE KBCategory: kbprg kbprb KBSubcategory: FxinteropDde

Last Reviewed: June 26, 1995