Excel: Reading the First DOS Environment VariableLast reviewed: November 3, 1994Article ID: Q69724 |
The information in this article applies to:
IMPORTANT: The CALL() and REGISTER() functions are provided for advanced users only. If you use these functions incorrectly you could accidentally cause errors in your system's operation.
SUMMARYIt is possible to retrieve the value of the first environment variable from the DOS environment string from within Microsoft Excel if you are running under Microsoft Windows. This is done using the CALL and REGISTER functions. One possible use for this would be to determine the directory from which Microsoft Windows was started.
MORE INFORMATIONThe DOS environment is an area of memory that DOS sets aside to store a series of ASCII strings. Each string in the environment is terminated by a byte of zero. The final string is terminated by two bytes of zero. The following Microsoft Excel macro returns the first substring in the MS-DOS environment string:
A1 Get_Environment A2 =REGISTER("KERNEL","GetDOSEnvironment","C") A3 =CALL(A2) A4 =RETURN()Note: The CALL function can also be used on a standard worksheet in Microsoft Excel versions 3.0 and later.
Adding Variable to Beginning of Environment StringTo arrange for a particular string to be placed at the beginning of the environment string, you must redefine all environment variables in a particular order. When an environment variable is first defined, its string is appended to the end of the existing environment string. If the variable was previously defined, it is deleted from its old position in the string and appended to the end. To retrieve an environment string called "CURDIR" that you set to the current directory before running Microsoft Windows, using the macro example above, do the following:
REFERENCES"Microsoft Excel Function Reference," version 4.0, pages 42-43, 350-352, 475-480 "Microsoft Excel Function Reference," version 3.0, pages 24, 193-194, 253-258 "Microsoft Excel for Windows Functions and Macros," version 2.1x, pages 255-256, 337-340
|
KBCategory: kbusage
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |