Professional Documents
Culture Documents
Case A Excel Gas Cooler
Case A Excel Gas Cooler
Case A Excel Gas Cooler
There may be several methods to deal with below issue. I am only suggesting one of them.
The purpose of this exercise is to simulate a gas cooler in hysys using VBA codes. Gas cooler shell
side fluid is a mix. of Methane and Ethane of known mass fraction, temperature, pressure and mass
flow rate. Outlet temperature and pressure are also known. Cooling water is provided as tube side
fluid with known temperature and pressure. Also outlet water pressure is known.
Refer Annexure 1_PFD. This sheet is a graphical representation of the given system.
All the input parameters are to be typed in this sheet (in YELLOW boxes). GREEN boxes are for hysys
calculated values (cooling water flow rate).
Refer Annexure 2_Input table. VBA program takes all the input parameters from this sheet.
There is no need to type anything in this sheet, as all the values are linked from Annexure_1_PFD.
Refer Annexure 3_output_table. This sheet receives the hysys calculated values. In this case, mass
flow rate of cooling water, process outlet stream mass fraction, density, viscosity calculated by
hysys are reported to this sheet by VBA codes. These values are linked to Annexure_1_PFD.
Refer Annexure 4_VBA_Code. Hysys model for this system is prepared. VBA code has been written
so that hysys takes the data from Annexure 2_Input table and provides calculated values in the
Annexure_3_output_table.
Prepared by:
Ajay S. Satpute
Sr. Process Engineer
Ramboll Oil & Gas, Qatar
Instructions:
1. This program shall work only if you have HYSYS installed in your PC AND
you have opened relevant hysys file.
2. Do not add or delete rows/columns in Annexure_2_Input_table or Annexure_3_output_table.
3. Prepare a simple PFD for this system. Type the input data (highlighted in YELLOW) as given in "Annexure_1_PFD".
4. Prepare a hysys file (preferably save it in the same folder and same file name as that of excel file).
5. In this file, go to VIEW, click on "Macros", Click on "Create". Name the Macro as StartHYSYS (you may choose any
name you want). Copy VBA codes from Annexure_4_VBA_Code worksheet to the Macro file.
6. Insert a rectangle from shapes. Type in it LinkToHysys (you may write any other text). Right click on the rectangle
and Click of "Assign Macro", which is StartHYSYS in this case.
7. Click on "LinkToHYSYS" tab in "Annexure_2_Input_table" worksheet.
8. Program shall open the hysys file (if license is available), receive values from "Annexure_2_Input_table" worksheet,
run the hysys file and export hysys calculated values from hysys to excel sheet. The graphical representation of the
results is shown in "Annexure_1_PFD" worsksheet.
LinkToHYSYS
Input Table:
Hysys stream number Description Temp. Pressure Flow rate Methane Ethane
mass mass
o
C 2
kg/cm g kg/h fraction fraction
Output Table:
Hysys stream number Description Temp. Pressure Flow rate Methane Ethane Mass
Viscosity,
mass mass density,
cP
o
C kg/cm2g kg/h fraction fraction kg/m3
' "Taking reference from worksheet Annexure 1_PFD, prepare a hysys file Snapshot is saved in Annexure_5_hysys_snapshot in
' "First define the streams (preferably all the strems in your hysys file"
Public PF_IN As ProcessStream
Public PF_OUT As ProcessStream
Public CW_IN As ProcessStream
Public CW_OUT As ProcessStream
Public pStream As ProcessStream
' "LOADING HYSYS SIMULATION FILE (This will open your hysys file as per path provided, if the hysys file is not open already)".
Set hyApp = CreateObject("HYSYS.Application")
hyApp.Visible = True
Set simCase = hyApp.ActiveDocument
If simCase Is Nothing Then
fileName = Worksheets("Annexure_2_Input_table").Range("B2") ' "Make sure your hysys file path is correct".
Compositions = PF_IN.ComponentMassFractionValue
Compositions(0) = Worksheets("Annexure_2_Input_table").Range("G6").Value ' "Make sure first component (Methane) mass
Compositions(1) = Worksheets("Annexure_2_Input_table").Range("H6").Value ' "Make sure second component (Ethane) ma
PF_IN.ComponentMassFraction.Values = Compositions
PRESPF_IN = Worksheets("Annexure_2_Input_table").Range("E6").Value ' "Make sure PF_IN input pressure is taken from co
PF_IN.Pressure.SetValue PRESPF_IN, "kg/cm2_g" ' "Pressure unit set is kg/cm2_g".
PRESPF_OUT = Worksheets("Annexure_2_Input_table").Range("E7").Value ' "Make sure PF_OUT input pressure is taken from
PF_OUT.Pressure.SetValue PRESPF_OUT, "kg/cm2_g" ' "Pressure unit set is kg/cm2_g".
PRESCW_IN = Worksheets("Annexure_2_Input_table").Range("E9").Value ' "Make sure CW_IN input pressure is taken from
CW_IN.Pressure.SetValue PRESCW_IN, "kg/cm2_g" ' "Pressure unit set is kg/cm2_g".
' Flow
Worksheets("Annexure_3_output_table").Range("F6").Value = CW_IN.MassFlow.GetValue("kg/h") ' "Hysys will calculate the m
' Pressure
Worksheets("Annexure_3_output_table").Range("E6").Value = CW_IN.Pressure.GetValue("kg/cm2_g") ' "Although it is an inp
' Viscosity
Worksheets("Annexure_3_output_table").Range("M7").Value = PF_OUT.Viscosity.GetValue("cP") ' "Hysys will calculate the m
End Sub