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 Vba In Excel For Reactor

hysys vba excel reactor

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

#1 DarkLord.Prem

DarkLord.Prem

    Brand New Member

  • Members
  • 3 posts

Posted 30 January 2015 - 02:14 AM

Hey guys, 

 

i have been stuck when i was trying to send over from excel towards HYSYS. i was able to do it for my material streams. but i am having problems with unit operations. in this case it is my plug flow reactors

 

'The aim of this module is ideally to input the design parameters of the unit ops in HYSYS
'Phase 1 : To Alter PFR Parameters
 
 
'codes based are similar to Material send.minor tweaks to suit specific UO
Sub RTR_Send()
 
 
Workbooks("Workbook Dump 4.0.1.xls").Activate
Dim hyCase As SimulationCase
Dim hyapp As HYSYS.Application
 
'dim each reactors changes
'based on the accord of 3pfrs to be altered at once
'more can be added if deemed necessary
 
Dim RTR1 As String
Dim RTR2 As String
Dim RTR3 As String
 
' DIM FOR reactor 1 properties
Dim delPress As Range
Dim TemperatureInlet As Range
Dim TemperatureOutlet As Range
Dim HeatFlow As Range
Dim ReactorVol As Range
Dim Voidage As Variable
Dim VoidVol As Range
Dim Length As Range
Dim Diam As Range
Dim Tube As Range
Dim Segment As Range
 
 
 
 
' STREAM 1 EDIT ZONE. FOR CELLS IN COL A AND B
 
Sheets("PFR").Select
 
RTR1 = Range("B2").Value
Set delPress = Worksheets("PFR").Range("B3")
Set TemperatureInlet = Worksheets("PFR").Range("B4")
Set TemperatureOutlet = Worksheets("PFR").Range("B5")
Set HeatFlow = Worksheets("PFR").Range("B6")
Set ReactorVol = Worksheets("PFR").Range("B7")
Set Voidage = Worksheets("PFR").Range("B8").Value
Set VoidVol = Worksheets("PFR").Range("B9")
Set Length = Worksheets("PFR").Range("B10")
Set Diam = Worksheets("PFR").Range("B11")
Set Tube = Worksheets("PFR").Range("B12")
Set Segment = Worksheets("PFR").Range("B13")
 
If RTR1 = "" Then
         Exit Sub
      End If
 
Set hyapp = CreateObject("HYSYS.Application")
Set hyCase = hyapp.ActiveDocument
 
 
hyCase.Flowsheet.PFReactors(CStr(RTR1)).VoidVolume.SetValue Voidage, "none" ' tired multiple sets unable to debug
 
 
 
 
End Sub
 


#2 Ajay S. Satpute

Ajay S. Satpute

    Gold Member

  • Members
  • 177 posts

Posted 01 February 2015 - 03:55 AM

Hi,

 

If I understand you correctly, then the problem you are facing is that; you need the codes to export PFR input values (e.g. Total Volume or Void Fraction etc.) from excel sheet to Hysys file.

 

1. To transfer from Excel to Hysys, pl. use below codes;

 

Public PFR_2 As PFReactor

Dim VoidFraction As Double
Dim TotalVolume As Double

Set PFR_2 = simCase.Flowsheet.Operations.ITEM("PFR_2")

 

 

PFR_2.VoidFraction = Worksheets("PFR").Range("J20").Value
PFR_2.TotalVolume = Worksheets("PFR").Range("J21").Value

 

'Note: PFR_2 is the name of the PFR.

'         Void fraction value saved at "J20" box in "PFR" sheet.

'         Total Volume value saved at "J21" box in "PFR" sheet.

 

2. To transfer from Hysys to Excel, pl. use below codes;

 

Worksheets("PFR").Range("K20").Value = PFR_2.VoidFraction
Worksheets("PFR").Range("K21").Value = PFR_2.TotalVolume

 

'This will transfer void fraction and total volume value from Hysys to Excel.

 

3. When you Type PFR_2. then several parameters get activated for you to select one of your interest.

 

 

 

Regards.

 

Ajay S. Satpute



#3 DarkLord.Prem

DarkLord.Prem

    Brand New Member

  • Members
  • 3 posts

Posted 01 February 2015 - 04:04 AM

Thank you for your input Ajay,

 

However as i am still building my reactors, i was hoping to let excel detect the PFR name from a cell value("B2") and then input the values into hysys after detecting the name in Excel. 

 

previous i defined the pfr name as a string . as defining it as an ITEM didnt work for me. 

 

please advice further

Hi,

 

If I understand you correctly, then the problem you are facing is that; you need the codes to export PFR input values (e.g. Total Volume or Void Fraction etc.) from excel sheet to Hysys file.

 

1. To transfer from Excel to Hysys, pl. use below codes;

 

Public PFR_2 As PFReactor

Dim VoidFraction As Double
Dim TotalVolume As Double

Set PFR_2 = simCase.Flowsheet.Operations.ITEM("PFR_2")

 

 

PFR_2.VoidFraction = Worksheets("PFR").Range("J20").Value
PFR_2.TotalVolume = Worksheets("PFR").Range("J21").Value

 

'Note: PFR_2 is the name of the PFR.

'         Void fraction value saved at "J20" box in "PFR" sheet.

'         Total Volume value saved at "J21" box in "PFR" sheet.

 

2. To transfer from Hysys to Excel, pl. use below codes;

 

Worksheets("PFR").Range("K20").Value = PFR_2.VoidFraction
Worksheets("PFR").Range("K21").Value = PFR_2.TotalVolume

 

'This will transfer void fraction and total volume value from Hysys to Excel.

 

3. When you Type PFR_2. then several parameters get activated for you to select one of your interest.

 

 

 

Regards.

 

Ajay S. Satpute



#4 DarkLord.Prem

DarkLord.Prem

    Brand New Member

  • Members
  • 3 posts

Posted 01 February 2015 - 04:48 AM

I have also encountered problems with the object not being defined. my PFRs are labelled from PFR-100 onwards. therefore when i tried to input that in together with some minor troubleshooting, the object was not able to be defined. 

 

thank you for your assistance



#5 Ajay S. Satpute

Ajay S. Satpute

    Gold Member

  • Members
  • 177 posts

Posted 01 February 2015 - 05:03 AM

Hi,

 

You may use IF-THEN command;

 

If Worksheets("PFR").Range("B2") = "PFR_2" Then
PFR_2.VoidFraction = Worksheets("PFR).Range("J20").Value
PFR_2.TotalVolume = Worksheets("PFR").Range("J21").Value
End If

 

'PFR_2 is just one of the PFRs. You could add another as PFR_3. But make sure you define the same as you did for PFR_2.

 

 

Regards.

 

Ajay S. Satpute



#6 Bobby Strain

Bobby Strain

    Gold Member

  • Members
  • 3,529 posts

Posted 01 February 2015 - 11:52 AM

You should get some sample codes from AspenTech support site. Ajay is quite helpful, but you want to start coding using good practice, not quick and dirty. The samples illustrate good practices in coding.

 

Bobby






Similar Topics