Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Importing Excell Variables into HYSYS using Visual Basic

Status
Not open for further replies.

CamoNZ

Chemical
Sep 4, 2008
3
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
 
Replies continue below

Recommended for you

There are no way without VBA.

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
 
Forgot to mention

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
 
Cheers Morten

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!
 
Im not sure i understand you concern?

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

 
Thanks for that extra code Morten..
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor