Coolprop function in Excel Macro (VBA)

1,259 views
Skip to first unread message

maxime...@institut-ps2e.com

unread,
Jun 23, 2015, 5:55:27 AM6/23/15
to coolpro...@googlegroups.com
Dear All, 

I am using Coolprop module for at least one year in Excel spreadsheet as an Excel Function and now I want to use the variety of function that coolprop offer me in a macro using VBA programming language. However at this moment could not succeed to import the Props function within this program. I think that the closest code I reach is following, 

Sub HTC_Calculation()
'
from CoolProp.CoolProp import Props

T = Props('C', 'T', 20 + 273, 'P', E8 * 100, 'air')

End Sub


I created this program from the ExcelTest sheet that is provided in the coolprop package for Microsoft Excel and I believe that I am not so far from the result but I could not find my solution on Coolprop website and on this public help group.

Thank you in advance for your help. 

Ian Bell

unread,
Jun 24, 2015, 11:16:59 AM6/24/15
to maxime...@institut-ps2e.com, coolpro...@googlegroups.com

You don't need the import line, that is for python. If the xlam is installed properly, you should only need to do PropsSI(...)

Also, the Props function is deprecated, you should use the PropsSI function.

--
You received this message because you are subscribed to the Google Groups "coolprop-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to coolprop-user...@googlegroups.com.
To post to this group, send email to coolpro...@googlegroups.com.
Visit this group at http://groups.google.com/group/coolprop-users.
For more options, visit https://groups.google.com/d/optout.

maxime...@institut-ps2e.com

unread,
Jun 24, 2015, 11:49:02 AM6/24/15
to coolpro...@googlegroups.com, maxime...@institut-ps2e.com

Thank you for your quick reply ! I am trying following code and I am getting following error. It look that Excel do not know this function, do you know why? 

Capture2.PNG

Ian Bell

unread,
Jun 24, 2015, 3:54:53 PM6/24/15
to maxime...@institut-ps2e.com, coolpro...@googlegroups.com
This works just fine for me:

Sub test()
Dim oo As Double
oo = PropsSI("T", "P", 101325, "Q", 0, "Water")
End Sub

Can you do the same call in a cell in your spreadsheet?

BTW, PropsSI uses all base-SI units (Pa, J, etc.)

--

fabianm...@gmail.com

unread,
May 11, 2016, 5:44:12 AM5/11/16
to coolprop-users, maxime...@institut-ps2e.com
Hello Ian,

I have the same problem. If I use your suggestion (PropsSI("T", "P", 101325, "Q", 0, "Water")), than I get the same error as maxime. I installed the newest version of coolprop for excel but i can't use the function in vba.

Ian Bell

unread,
May 11, 2016, 9:17:22 AM5/11/16
to coolpro...@googlegroups.com
A) When you put PropsSI("T", "P", 101325, "Q", 0, "Water") into a cell in an Excel spreadsheet, does that work and give you something like 373....?

B) Can you send me a screenshot of your vba window to ian.h...@gmail.com

Marco Carrilho Diniz

unread,
Jul 23, 2016, 3:32:41 PM7/23/16
to coolprop-users
Hello Maxime, Fabian and Ian,

I just had the same problem you were discussing about. The function can't be used unless you tell your VBA code where it is defined. The solution is described here:


Kind regards,

Marco.

Ian Bell

unread,
Jul 24, 2016, 9:39:53 PM7/24/16
to coolpro...@googlegroups.com
Interesting.  Can you please modify the VBA we provide with this fix and email it to me at ian.h...@gmail.com?

Thanks,
Ian

Marco Carrilho Diniz

unread,
Jul 26, 2016, 11:58:09 AM7/26/16
to coolprop-users
Hi Ian,

Actually it was not necessary to modify the VBA you provide. What I did was to rename the VBA (like explained in the tutorial I posted before) and after this I had to set the reference to the add in the specific workbook I was working on. Maybe there is another more versatile solution to the problem, but is this case the problem was fixed by changing only Excel configurations.

Marco. 

Ian Bell

unread,
Jul 26, 2016, 9:10:07 PM7/26/16
to coolpro...@googlegroups.com
Right, can you please mail me the modified spreadsheet with the fix?

Marco Carrilho Diniz

unread,
Aug 15, 2016, 6:25:09 PM8/15/16
to coolprop-users
Hi Ian, just sent you the modified spreadsheet.

Ian Bell

unread,
Aug 28, 2016, 9:09:15 PM8/28/16
to coolpro...@googlegroups.com
Our provided XLAM now has the appropriate project name: VBAProject --> CoolProp

Ian

To unsubscribe from this group and stop receiving emails from it, send an email to coolprop-users+unsubscribe@googlegroups.com.
To post to this group, send email to coolprop-users@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages