Jump to content



Featured Articles

Check out the latest featured articles.

File Library

Check out the latest downloads available in the File Library.

New Article

Product Viscosity vs. Shear

Featured File

Vertical Tank Selection

New Blog Entry

Low Flow in Pipes- posted in Ankur's blog

Export/import Data From/to Hysys/excel


This topic has been archived. This means that you cannot reply to this topic.
3 replies to this topic
Share this topic:
| More

#1 Ajay S. Satpute

Ajay S. Satpute

    Gold Member

  • Members
  • 177 posts

Posted 02 July 2013 - 11:45 PM

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

 

 

Attached Files



#2 Gopal Sutar

Gopal Sutar

    Brand New Member

  • Members
  • 1 posts

Posted 03 July 2013 - 01:09 AM

Hi Ajay,

 

Please ensure that Hysys library type is selected in VBA. 

Open the VBA. Go to Tools>References, and select 'Hysys Vxx type library'.

 

Regards,

Gopal



#3 Ajay S. Satpute

Ajay S. Satpute

    Gold Member

  • Members
  • 177 posts

Posted 03 July 2013 - 01:38 AM

Thanks Gopal for the quick help. I did what you suggested.

 

I don't get the earlier error message anymore. But new error message says "Compile error: variable not defined". PFA new error message.

 

Thanks and regards.

 

Ajay

Attached Files



#4 Alexsandres

Alexsandres

    Junior Member

  • Members
  • 27 posts

Posted 11 July 2013 - 04:29 AM

Ajay,

 

I've check your simulation. VBA needs every parameter to be declared before executing. And you've not declared "PRESSREAM1", and another parameter.

 

 

I've made a correction for you, please revise your code as following

 

Public Sub StartHYSYS()
Dim filename As String
Dim ITEM As Integer
Dim PRESSTREAM1 As Double, FLOWSTREAM1 As Double, TEMPSTREAM1 As Double
Dim STREAM1 As Streams, STREAM2 As Streams
 
' 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





Similar Topics