×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Importing Excell Variables into HYSYS using Visual Basic

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

RE: Importing Excell Variables into HYSYS using Visual Basic

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

RE: Importing Excell Variables into HYSYS using Visual Basic

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

RE: Importing Excell Variables into HYSYS using Visual Basic

(OP)
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!  

RE: Importing Excell Variables into HYSYS using Visual Basic

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

 

RE: Importing Excell Variables into HYSYS using Visual Basic

(OP)
Thanks for that extra code Morten..

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources