Importing Excell Variables into HYSYS using Visual Basic
Importing Excell Variables into HYSYS using Visual Basic
(OP)
Hi
I would really appreciates some help with importing a variable from excel into HYSYS.
I have no trouble accessing the variable from excel, but how do I then send this into HYSYS. I just need to update one flow rate in a material stream??
Thanks very much
I would really appreciates some help with importing a variable from excel into HYSYS.
I have no trouble accessing the variable from excel, but how do I then send this into HYSYS. I just need to update one flow rate in a material stream??
Thanks very much





RE: Importing Excell Variables into HYSYS using Visual Basic
Remember to reference the HYSYS libraries.
Then in essense its about OLE interface (i think its called)
I usually use a HYSYS spreadsheet to change values because i find it easier. Some HYSYS variables needs to be changed using "monikers" or "backdoor variables" that requires knowledge of some specific codes that are a little hard to obtain - but most can be changed via a spreadsheet using a single line taht could look like this:
spd.Cell("b2").CellValue = oldt 'sets t2 (adiabatic mix temp)
This is from something i made and sets the temperature for a stream to a valued stored in a local variable "oldt" that i read from the spreadsheet.
Best regards
Morten
RE: Importing Excell Variables into HYSYS using Visual Basic
spd is an object defined like this:
Dim spd, spd2 As Object
and initialised like this:
Set spd = hyCase.Flowsheet.Operations.Item("SPRDSHT-1")
Best regards
Morten
RE: Importing Excell Variables into HYSYS using Visual Basic
That worked perfectly. Now to complete the macro, I need to simulate clicking an item from the add ins menu.
There is an option called calculate in the add ins menu which performs some calculations and alters the excel spread sheet. I need for this to automatically be clicked somehow?
Any ideas on how to do this?
Thanks very much for your help!
RE: Importing Excell Variables into HYSYS using Visual Basic
Excel allways update - except the solver - and so should HYSYS when you change something.
My only problem has been that excel may itterate faster that HYSYS can solve.
So for this i added these lines at critical points:
Do
If hyCase.Solver.IsSolving = False Then
Exit Do
End If
Loop
This prevents the excel macro to progress if HYSYS hasnt finished e.g. if a recycle unit is active.
I dont think this is what you are looking four but i dont understand your question.
Best regards
Morten
RE: Importing Excell Variables into HYSYS using Visual Basic