Dear all,
I really need your help to figure out why my VBA code are not working, what am I doing incorrect.
Please see the hysys snap shot file. Component is WATER (mole fraction is defined in hysys).
I want to export temp., pressure and flow of STREAM1 from excel file to hysys file
and import temp., pressure and flow of STREAM2 from hysys file to excel file.
Going through aspentech supoort site, different blogs and cheresources, I could write below codes;
Option Explicit
Public hyApp As HYSYS.Application
Public simCase As SimulationCase
Public pStream As ProcessStream
Public Sub StartHYSYS()
Dim filename As String
Dim ITEM As Integer
' LOADING HYSYS SIMULATION FILE
Set hyApp = CreateObject("HYSYS.Application")
hyApp.Visible = True
Set simCase = hyApp.ActiveDocument
If simCase Is Nothing Then
filename = Worksheets("HYSYS").Range("C4").Text
If filename <> "False" And simCase Is Nothing Then
Set simCase = GetObject(filename, "HYSYS.SimulationCase")
simCase.Visible = True
End If
End If
Set pStream = simCase.Flowsheet.MaterialStreams.ITEM("STREAM1")
PRESSTREAM1 = Worksheets("HYSYS").Range("D9").Value
STREAM1.Pressure.SetValue PRESSTREAM1, "kg/cm2_g" ' export pressure
FLOWSTREAM1 = Worksheets("HYSYS").Range("D10").Value
STREAM1.MassFlow.SetValue FLOWSTREAM1, "kg/h" ' export mass flowrate
TEMPSTREAM1 = Worksheets("HYSYS").Range("D8").Value
STREAM1.TempFlow.SetValue TEMPSTREAM1, "C" ' export Temperature
Set pStream = simCase.Flowsheet.MaterialStreams.ITEM("STREAM2")
Worksheets("HYSYS").Range("E8").Value = STREAM2.Temperature.GetValue("C") ' import data TEMPERATURE from hysys streams
Worksheets("HYSYS").Range("E9").Value = STREAM2.Pressure.GetValue("kg/cm2_g") ' import data TEMPERATURE from hysys streams
Worksheets("HYSYS").Range("E10").Value = STREAM2.MassFlow.GetValue("kg/h") ' import data TEMPERATURE from hysys streams
' FINISH
End Sub
It is giving error, "Complie error: User defined type not define". PFA error snap shot file.
I would be very grateful if someone can help.
Regards.
Ajay