views:

54

answers:

2

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

The location of the various config files used by the addins is determined at startup time by a number of environment variables. I'd like to debug a problem related to these environment variables by the most direct possible means: Can I simply type in an Excel formula which will cause an environment variable to display in the worksheet?

Let me give you an example:

I have an environment variable called "MYADDIN_XML_CONFIG" which contains the path to an XML file used by the MyAddin component. If this environment variable is set incorrectly then MyAddin will fail to run. I'd like to have a single simple function which takes the string "MYADDIN_XML_CONFIG" as an argument and returns the value of the env-var if it is set. If the environment variable is not set it should return a NONE or some kind of error code.

Can this be done?

FYI, MS Excel 2003 on Windows XP.

+2  A: 

I don't know any 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 user-defined formula in a worksheet, e.g.

=Env("COMPUTERNAME")
Joe
+1  A: 

Use the VBA function Environ("MYADDIN_XML_CONFIG").

Julien Lebosquain