Document Type: Programming

HP VEE and Microsoft Excel DDE Example

Keywords: VEE, Excel, DDE


Purpose:

This document covers DDE communication between HP VEE and Microsoft Excel running on a
Windows 95/NT PC. This example shows how to open a pre-existing Excel spreadsheet, write
data to that spreadsheet, then save the file.

Language:

HP VEE

Operating System:

Windows 95/NT

Required Products:

Microsoft Excel 95 or 97
HP VEE 4.x, 5.x

Results:

When the VEE program is executed, Excel should start minimized on
the taskbar. VEE will write data to the spreadsheet and make Excel
visible before saving and exitting. Make sure that the Windows
path statement is set to include the location of EXCEL.EXE. In
Windows 95, this can be set in the AUTOEXEC.BAT file. In Windows
NT this is set in the Control Panel->System. If the path is not
included, error 830 can result.

Program:

  
  |--------------------- To/From DDE --------------------------|
  |------------------------------------------------------------|
  |  Application: Excel                                        |
  |  Topic:       System                                       |
  |  Timeout:     5                                            |
  |------------------------------------------------------------|
  |  Execute Cmnd: "[OPEN(\"C:\\MY DOCUMENTS\\MYDATA.XLS\")]"  |
  |------------------------------------------------------------|
                               |
                               |
                               |
  |--------------------- To/From DDE --------------------------|
  |------------------------------------------------------------|
  |  Application: Excel                                        |
  |  Topic:       MYDATA                                       |
  |  Timeout:     5                                            |
  |------------------------------------------------------------|
  |  Write Item: "R1C1" Text X Str                             |
  |------------------------------------------------------------|
                               |
                               |
                               |
  |--------------------- To/From DDE --------------------------|
  |------------------------------------------------------------|
  |  Application: Excel                                        |
  |  Topic:       System                                       |
  |  Timeout:     5                                            |
  |------------------------------------------------------------|
  |  Execute Cmnd: "[APP.RESTORE]"                             |
  |  Execute Cmnd: "%FXY"                                      |
  |------------------------------------------------------------|


  The first "To/From DDE" object launches and initiates communication
  to Excel. It then executes the command to open the specified file. The
  filename is embedded with quotes. The Excel syntax would be 
            [OPEN("C:\MY DOCUMENTS\MYDATA.XLS")]
  but VEE requires the backslashes be entered to have the quotes and directory
  slashes to be sent.

  The second object writes data to the file. Application note 2120-1 and 
  2120-2 go into further detail on writing data to Excel. This example
  writes a single value into the cell at row 1 column 1.

  The third object closes the file. Although there are other ways using macros
  to save the program, this is a fairly straight forward approach. The object
  emulates keystrokes to activate menu items to exit the program. Before this
  keystroke emulation can begin, the application must be restored to a visible
  state (ie, non-minimized). The %FXY is sent to Excel. This emulates selecting
  the file menu, then eXit, then pressing the Yes button to save the file. The
  exact interpretation of the string is ALT(%)-File(F)-Exit(X)-Yes(Y).

  If the programmer wanted to save the progam into a different filename, then the
  third object would become:

  |--------------------- To/From DDE -----------------------------|
  |---------------------------------------------------------------|
  |  Application: Excel                                           |
  |  Topic:       System                                          |
  |  Timeout:     5                                               |
  |---------------------------------------------------------------|
  |  Execute Cmnd: "[APP.RESTORE]"                                |
  |  Execute Cmnd: "[SAVE.AS(\"C:\\MY DOCUMENTS\\NEWDATA.XLS\")]" |
  |  Execute Cmnd: "%FX"                                          |
  |---------------------------------------------------------------|

Download this example program VEE_EX.VEE


Revision 1.0 15 Dec 98 lec

Copyright Hewlett-Packard Company 1998
This information is subject to change without notice and is provided "as is" with no warranty.
Hewlett-Packard shall not be liable for any direct, indirect, special, incidental or consequential damages in connection with the use of this material.