How can I display the operating system environment variable from Excel?

I have an application written in Excel plus a bunch of C ++ / Python additions.

The location of the various configuration files used by add-ons is determined at startup time by several environment variables. I would like to debug the problem with these environment variables in the most direct way possible: can I just enter an Excel formula that will display the environment variable in the worksheet?

Let me give you an example:

I have an environment variable called MYADDIN_XML_CONFIG that contains the path to the XML file used by the MyAddin component. If this environment variable is not set correctly, MyAddin will not work. I would like to have one simple function that takes the string " MYADDIN_XML_CONFIG " in as an argument and returns env-var if set.If no environment variable is set, it should return NONE or some error code.

Can this be done?

FYI, MS Excel 2003 on Windows XP.

+2


source to share


2 answers


I don't know of a built-in Excel formula that does this, but you can create a public function in a VBA module:

Public Function Env(Value As Variant) As String
    Env = Environ(Value)
End Function

      



then use this as a custom formula on a worksheet like

=Env("COMPUTERNAME")

      

+5


source


Use a VBA function Environ("MYADDIN_XML_CONFIG")

.



+1


source







All Articles