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

Hysys Data Export To Excel

hysys vba

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

#1 LiveFree

LiveFree

    Brand New Member

  • Members
  • 7 posts

Posted 29 April 2013 - 02:44 PM

I am creating a workbook that will import material stream component flows (Mass, Molar, and Volumetric) from HYSYS.  I have written 90% of the code, but cannot get part of it to work correctly.  I would use HYSYS Stream Reader for this, but I want this workbook to be able to pull the data, format it, and print it according to a template I have created.  I'll paste the code below:
 
 
Private Sub CommandButton1_Click()
Dim hycase As Object
Dim hyStream As ProcessStream
Dim Feed1, Feed2, Feed3, Feed4, Feed5, Feed6, Propane, Butane, Alkylate As String
Dim noCount As Integer
'Connect to HYSYS (must be open with target Case loaded)
Set hyapp = GetObject(, "HYSYS.Application")
hyapp.Visible = True
Set hycase = hyapp.ActiveDocument
'Get case name
Set CaseName = hycase.Title
Set hyFS = hycase.Flowsheet
Set hyOPers = hyFS.Operations
'Get reaction variables
Set Composite = hyFS.MaterialStreams("8")
Set Effluent = hyFS.MaterialStreams("9")
Set Contactors = hyOPers.Item("Contactors")
Set Data = Worksheets("Sheet1")
Set OP = Worksheets("Output")
 
OP.Cells(1, 7).Value = CaseName
 
Worksheets("Sheet1").Activate
 
Feed1 = Data.Cells(3, 2).Value
Feed2 = Data.Cells(4, 2).Value
Feed3 = Data.Cells(5, 2).Value
Feed4 = Data.Cells(6, 2).Value
Feed5 = Data.Cells(7, 2).Value
Feed6 = Data.Cells(8, 2).Value
Propane = Data.Cells(3, 5).Value
Butane = Data.Cells(4, 5).Value
Alkylate = Data.Cells(5, 5).Value
 
Cells(11, 11).Value = Feed1
    If Feed1 <> "" Then
    
        Set hyStream = hyFS.MaterialStreams.Item(Feed1)
 
        For noCount = 1 To 55
            MolarFlow = hyStream.ComponentMolarFlowValue
            Worksheets("Output").Activate
            Cells(noCount + 5, 2) = MolarFlow(noCount - 1) * 3600
                  
         Next noCount
 
    End If
End Sub

 

 

Regarding the red text, Feed1 is equal to "1", or stream 1 in this case.  It is imput on another spreadsheet as a feed stream to be pulled into the spreadsheet.  The way the code is currently written, when run, it fills cells B6-B60 with the value -117961200.  However, when I replace Feed1 with "1", the macro fills the pertinent cells with the correct values (kgmol/hr of the corresponding component).  What am I missing here?  I've tried converting Feed1 to a string but that did not work either.



#2 Bobby Strain

Bobby Strain

    Gold Member

  • Members
  • 3,529 posts

Posted 29 April 2013 - 04:26 PM

Here is a code snippet to resolve your impass. Streams are referenced either by item number (starting with 0) or name.

 

Bobby

 

 

Attached Files



#3 LiveFree

LiveFree

    Brand New Member

  • Members
  • 7 posts

Posted 30 April 2013 - 01:46 PM

Fantastic.  Thanks for the help!



#4 Ajay S. Satpute

Ajay S. Satpute

    Gold Member

  • Members
  • 177 posts

Posted 30 April 2013 - 11:14 PM

Dear LiveFree,

 

I have never done this activity (creating a workbook that will import material stream component flows etc.). However, I want to learn it.

 

Is it possible for you to share/send the hysys and excel file please?

 

Thanks.

 

Ajay



#5 Bobby Strain

Bobby Strain

    Gold Member

  • Members
  • 3,529 posts

Posted 01 May 2013 - 10:11 AM

Ajay,

   Presuming you are a licensed user, there is lots of stuff at the AspenTech support site for you.

 

Bobby


Edited by Bobby Strain, 01 May 2013 - 10:11 AM.


#6 Ajay S. Satpute

Ajay S. Satpute

    Gold Member

  • Members
  • 177 posts

Posted 02 May 2013 - 07:35 AM

Dear Bobby,

 

I have checked Aspen tech support website, but it didn't help much.

 

If someone can share the hysys file and excel file with probably a method of how to create a workbook that will import material stream component flows (Mass, Molar, and Volumetric) from HYSYS, then it would be great.

 

Thanks.

 

Ajay



#7 Bobby Strain

Bobby Strain

    Gold Member

  • Members
  • 3,529 posts

Posted 02 May 2013 - 10:14 AM

Ajay,

   You didn't look hard enough. You should find both a workbook dump and stream reporter, ready for you to use. And learn by looking at the code.

 

Bobby


Edited by Bobby Strain, 02 May 2013 - 10:14 AM.


#8 Alexsandres

Alexsandres

    Junior Member

  • Members
  • 27 posts

Posted 03 May 2013 - 01:36 AM

Ajay,

 

I've created what you're looking for. Just open http://hysyssimulations.blogspot.com

 

Alex



#9 Ajay S. Satpute

Ajay S. Satpute

    Gold Member

  • Members
  • 177 posts

Posted 04 May 2013 - 10:45 PM

Thanks Alex. :)

 

Regards.

 

Ajay



#10 ahmed_ngl89

ahmed_ngl89

    Brand New Member

  • Members
  • 1 posts

Posted 08 May 2013 - 05:52 PM

excuse me guys can any one solve my problem???? i made a simulation program using matlab for  multi component distillation and i made comparison with hysys so there is a huge difference between them can any one solve my problem???please



#11 Bobby Strain

Bobby Strain

    Gold Member

  • Members
  • 3,529 posts

Posted 08 May 2013 - 06:48 PM

Ahmed,

    You should use HYSYS results as most accurate. Assuming you are using the proper EOS, etc. It might help if you gave us a clue about the particular simulation.

 

Bobby






Similar Topics