Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

9/26/2017 Hysys Training to Link Hysys Valve to Excel

HOME ABOUT CONTACT

HYSYS EXCEL AUTOMATION


Hysys Excel Automation Training

Hysys Training to Link Hysys Valve to Excel

facebook

Linking Hysys Simulation to access HYSYS UNIT OPERATION VALVE

using VBA macro.

Here is the source code:

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Option Explicit

Public hyApp As HYSYS.Application

Public simCase As SimulationCase

Public FEED1 As ProcessStream, FEED2 As ProcessStream

Public Sub StartHYSYS

()

Dim fileName As String

Dim PRESSFEED2 As Double, FLOWFEED2 As Double, TEMPFEED2 As Double

Dim VALVE1 As Valve, VALVE2 As Valve

Dim PRESSDROP1 As Double

' LOADING HYSYS SIMULATION FILE

Set hyApp = CreateObject("HYSYS.Application")

hyApp.Visible = True

Set simCase = hyApp.ActiveDocument

If simCase Is Nothing Then

fileName = Worksheets("Sheet1").Range("c2")

http://hysyssimulations.blogspot.in/2011/06/how-to-link-hysys-simulation-to-excel_10.html 1/4
9/26/2017 Hysys Training to Link Hysys Valve to Excel

If fileName <> "False" And simCase Is Nothing Then

Set simCase = GetObject(fileName, "HYSYS.SimulationCase")

simCase.Visible = True

End If

End If

Set FEED1 = simCase.Flowsheet.MaterialStreams.Item("FEED1")

Worksheets("Sheet1").Range("D6").Value = FEED1.MassFlow.GetValue("LB/HR") ' import data MASS FLOWRATE from hysys simulation streams

Worksheets("Sheet1").Range("D7").Value = FEED1.Pressure.GetValue("PSIG") ' import data PRESSURE from hysys tutorial streams

Worksheets("Sheet1").Range("D8").Value = FEED1.Temperature.GetValue("C") ' import data TEMPERATURE from hysys tutorial streams

Set FEED2 = simCase.Flowsheet.MaterialStreams.Item("FEED2")

PRESSFEED2 = Worksheets("Sheet1").Range("H7").Value

FEED2.Pressure.SetValue PRESSFEED2, "PSIA" ' export pressure

FLOWFEED2 = Worksheets

("Sheet1").Range("H6").Value

FEED2.MolarFlow.SetValue FLOWFEED2, "MMSCFD" ' export molar flowrate

TEMPFEED2 = Worksheets("Sheet1").Range("H8").Value

FEED2.Temperature.SetValue TEMPFEED2, "F" ' export temperature

'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Set VALVE1 = simCase.Flowsheet.Operations.Item("VALVE-1")

PRESSDROP1 = Worksheets("Sheet1").Range("D16").Value

VALVE1.PressureDrop.SetValue PRESSDROP1, "inHg(60F)" ' send data pressure drop to hysys

Worksheets("Sheet1").Range("D12").Value = FEED1.Pressure.GetValue("psia") ' get data from hysys simulation

Worksheets("Sheet1").Range("D13").Value = FEED1.Pressure.GetValue("inHg(60F)") ' get data from hysys tutorial

Worksheets("Sheet1").Range("D14").Value = FEED1.Temperature.GetValue("c") ' get data from hysys tutorial

Worksheets("Sheet1").Range("D15").Value = FEED1.Temperature.GetValue("r") ' get data from hysys tutorial

Worksheets("Sheet1").Range("D18").Value = VALVE1.PressureDrop.GetValue("mmHg(0C)") ' get data from hysys simulation

Worksheets("Sheet1").Range("D19").Value = VALVE1.PressureDrop.GetValue("bar") ' get data from hysys simulation

Worksheets("Sheet1").Range("D20").Value = VALVE1.PressureDrop.GetValue("kPa") ' get data from hysys tutorial

Worksheets("Sheet1").Range("D21").Value = VALVE1.PressureDrop.GetValue("atm") ' get data from hysys tutorial

Worksheets("Sheet1").Range("D22").Value = VALVE1.PressureDrop.GetValue("psi") ' get data from hysys tutorial

http://hysyssimulations.blogspot.in/2011/06/how-to-link-hysys-simulation-to-excel_10.html 2/4
9/26/2017 Hysys Training to Link Hysys Valve to Excel

End Sub

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

HYSYS simulation and excel file can be downloaded here. REMEMBER TO CHANGE HYSYS SIMULATION DIRECTORY ADDRESS ON CELL "C2"

Note: Hysys simulation is generated by Hysys V7.1, may not work well in previous version of Hysys, s.a Hysys 2006 or Hysys 3.2.

If Hysys V7.1 is not available, make your own simulation. Stream FEED1 and FEED2 specification can be found in previous post . Read and simulate previous post, add two Valves named "VALVE-

1" and "VALVE-2", add two more streams and named "OUT-1" and "OUT-2".

Save in a specific folder/directory you like.

MAKE SURE TO WRITE DIRECTORY ADDRESS TO CELL "C2" OR HYSYS FILE WILL NOT BE FOUND.

Make some test. Input pressure drop in Cell "D16", and click "RUN HYSYS".

hysys training , hysys tutorial

RELATED POSTS

http://hysyssimulations.blogspot.in/2011/06/how-to-link-hysys-simulation-to-excel_10.html 3/4
9/26/2017 Hysys Training to Link Hysys Valve to Excel

Hysys Training to Link Hysys Valve to Excel Hysys Tutorial to Link Hysys Streams on Excel

How to create and acces molar component (molar flowrate, com...

Links to this post

Create a Link

New New New New

http://hysyssimulations.blogspot.in/2011/06/how-to-link-hysys-simulation-to-excel_10.html 4/4

You might also like