Have a Question?
Print

00389: Program example demonstrating communicating with MS Excel via DDE

Title:

Program example demonstrating communicating with MS Excel via DDE

Description:

Please note that the Excel file must be opened first before DDE is able to access it. 

VPRO/5 example: 

0010 REM ***** This program instructs Excel to open the
0020 REM spreadsheet file specified on line 50. On line 80,
0030 REM it tells it to make worksheet 2 of that spread-
0040 REM sheet file active, and then will read the contents
0050 REM of the Row1, Column 1 and print it to the screen.
0060 OPEN (1,MODE="DDECLIENT")"EXCEL:SYSTEM"
0070 LET CMD$="[OPEN(""c:\temp\book1.xls"")]"+$00$
0080 WRITE RECORD(1,KEY="DDE_EXECUTE")CMD$
0090 CLOSE (1)
0100 OPEN (1,MODE="DDECLIENT")"EXCEL:c:\temp\book1.XLS:sheet2"
0110 READ RECORD(1,KEY="R1C1")T$; PRINT "A1: ",T$

In this example, the file is opened first, the channel is closed, and then we open the file again. The only reason this works is because we opened the file in the first place. Notice that when we close the channel in line 90, it does not close the file in Excel. (book1.xls is still open) When we try to open it again, it is already open in Excel, so it works.

BBj Rev 2.x and up.

Add alias Jname to config.bbx:

ALIAS Jname com.basis.plugin.DDEOpenPlugin

Above program sample with appropriate changes for BBj:

0010 REM ***** This program instructs Excel to open the
0020 REM spreadsheet file specified on line 50. On line 80,
0030 REM it tells it to make worksheet 2 of that spread-
0040 REM sheet file active, and then will read the contents
0050 REM of the Row1, Column 1 and print it to the screen.
0060 OPEN (1,MODE="DDECLIENT=EXCEL:SYSTEM")"J0"
0070 LET CMD$="[OPEN(""c:\temp\book1.xls"")]"+$00$
0080 WRITE RECORD(1,KEY="DDE_EXECUTE")CMD$
0090 CLOSE (1)
0100 OPEN (1,MODE="DDECLIENT=EXCEL:c:\temp\book1.XLS:sheet2")"J0"
0110 READ RECORD(1,KEY="R1C1")T$; PRINT "A1: ",T$
Table of Contents