Contents - Index


Executing EES Macro Commands from EXCEL

 

This EXCEL sheet contains a macro that will call EES using Dynamic Data Exchange.  It should serve as a model of how EES and EXCEL can interact. Note that EES can also communicate with EXCEL directly with macro commands as shown in the Macro file discussion

 

The macro will start EES and open the file C:\ees32\examples\EXCEL_EES.ees.  It will then copy two columns of data representing temperature and pressure to the clipboard, paste them into the first two columns of the EES Parametric table 'Table 1', solve the table and copy the calculated results back to the clipboard.  In this case, the calculated results are the specific enthalpy, entropy, and volume for refrigerant R134a. The EXCEL macro then paste the result into the EXCEL sheet and quits EES.  The EXCEL macro is executed when the Calculate button in the Visual Basic form is clicked.  The EXCEL example and the EES file that it executes are in the EES32\Examples folder with file name EXCEL_EES.xls and EXCEL_EES.ees.

 

Private Sub cmdDDE_Click()

    Dim ChannelNumber As Integer

    Dim myShell As String

    

    ChannelNumber = -1

    myShell = frmEESDDE.txtApp.Text

    

    On Error Resume Next

    

    'Copy selected rows into clipboard which will be pasted into a Parametric Table in EES'

    Range("A17:B26").Select

    Selection.Copy

 

    'Open EES

    Shell_R = Shell(myShell, 1)

    

    If Shell_R <> "" Then

        'Initiate DDE

        ChannelNumber = Application.DDEInitiate(app:="ees", topic:="")

    

        If ChannelNumber <> -1 Then

            Application.DDEExecute ChannelNumber, "[Open C:\EES32\Examples\EXCEL_EES.ees]"

            Application.DDEExecute ChannelNumber, "[Paste Parametric 'Table 1' R1 C1]"

            Application.DDEExecute ChannelNumber, "[SOLVETABLE 'TABLE 1', Rows=1..10]"

            Application.DDEExecute ChannelNumber, "[COPY ParametricTable 'Table 1' R1 C3:R10 C5]"

            'Paste results from EES into EXCEL'

            ActiveSheet.Paste Destination:=Worksheets("Sheet1").Range("C17:E26")

            'Quit EES and Terminate DDE

            DDEExecute ChannelNumber, "QUIT"

            Application.DDETerminate ChannelNumber

        Else

            MsgBox "Unable to initiate connection to EES", vbExclamation, "EES DDE"

        End If

            

        frmEESDDE.Hide

        

    Else

            MsgBox "The application, " & myShell & ", was not found", vbExclamation, "EES DDE"

    End If

 

End Sub

 

A listing of the EES program EXCEL_EES.ees appears below.

____________________________

 

"This example provides an example of how EES can be called from EXCEL using Dynamic Data Exchange (DDE) and the Macro command ability in EES.  Macro commands and DDE are only available in the Professional license.  If you have a Professional license and you wish to run this example, close EES, start EXCEL and open the EESDDE.xls file.  The EXCEL macro will: 1) start EES; 2) open this file; 3)  copy 10 runs of temperature and pressure values and paste them into the Parametric table;  4)  Solve the table; and 5) copy the calculated values of h, s, and v back into EXCEL."

 

R$='R134a'

 

h=enthalpy(R$,T=T,P=P)

s=entropy(R$,T=T,P=P)

v=volume(R$,T=T,P=P)