Is it possible to call CoolProp from Excel VBA?

61 views
Skip to first unread message

Fausto A. A. Barbuto

unread,
Sep 27, 2021, 10:27:51 PM9/27/21
to coolpro...@googlegroups.com

Hi,

I've been trying to call PropsSI from VBA but no joy so far. I wrote a typical function like:

Public Function ExecCoolProp()
    Dim Wksht1 As Worksheet

    Set Wksht1 = Worksheets("Sheet1")

    Wksht1.Range("F10") = CoolProp.PropsSI("d(T)/d(P)|H", "T", 300, "P", 350000, "CH4")
End Function


that should write (dT/dp) for constant H and (p,T) = (350000 Pa, 300 K) into cell F10 of worksheet Sheet1. But I get a runtime error 424 (Object required) instead. However, if I write

=CoolProp.PropsSI("d(T)/d(P)|H", "T", 300, "P", 350000, "CH4")

into any regular worksheet cell, it returns a value that seems valid (4.3079E-06).

What's the problem? Function ExecCoolProp() should "see" CoolProp and its procedures. But that doesn't seem to be the case. Is that because CoolProp is "public" for cell (worksheet) use but "private" at VBA level?

Thanks for any enlightenment on this topic.

Fausto

Clifford Bradford

unread,
Dec 9, 2024, 5:11:53 PM12/9/24
to coolprop-users
to call an Excel function from VBA you need to write something like:
Application.WorksheetFunction."functionname"
Reply all
Reply to author
Forward
0 new messages