Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default How do I use environment variables in Excel?

I've defined some environment variables that I want to use to specify a path
to a directory. How do I use these environment variables in the "Save As"
box?

The variables a

"ADCmath" set to "P:\blah"
"TERM" set to "Fall2004"

I want to save an Excel file in the directory P:\blah\Fall2004 by using
%ADCmath%\%TERM%\filename.xls

but it doesn't work.

(And how can something so simple in UNIX be so obtuse in Windows???)

Ken
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,120
Default How do I use environment variables in Excel?

Why do you expect Excel to have the same syntax as Unix? That is just
perverse

EnvString = Environ(Indx)

where indx can be the index number of the value, such as Term

--
HTH

-------

Bob Phillips
"kfloyd" wrote in message
...
I've defined some environment variables that I want to use to specify a

path
to a directory. How do I use these environment variables in the "Save As"
box?

The variables a

"ADCmath" set to "P:\blah"
"TERM" set to "Fall2004"

I want to save an Excel file in the directory P:\blah\Fall2004 by using
%ADCmath%\%TERM%\filename.xls

but it doesn't work.

(And how can something so simple in UNIX be so obtuse in Windows???)

Ken



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 109
Default How do I use environment variables in Excel?

Try ActiveWorkbook.SaveAs Filename:=ADCMath & "\" & Term & "\" &
ActiveWorkbook.Name

"kfloyd" wrote:

I've defined some environment variables that I want to use to specify a path
to a directory. How do I use these environment variables in the "Save As"
box?

The variables a

"ADCmath" set to "P:\blah"
"TERM" set to "Fall2004"

I want to save an Excel file in the directory P:\blah\Fall2004 by using
%ADCmath%\%TERM%\filename.xls

but it doesn't work.

(And how can something so simple in UNIX be so obtuse in Windows???)

Ken

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 694
Default How do I use environment variables in Excel?

This only works in DOS, maybe Windows, (and UNIX as Bob mentioned), and
unfortunately not in Excel.
The Environ() function returns Local and System environment variable, with
Local taking precedence, ie returns Local if the variable exists at Local and
Sytem level, but i don't think it returns 'session' environment variables
(the ones you create for example in a Command Prompt session, which disappear
when you close it. However i am not completely sure about that.

You could create a function to substitute environment variables in any string:
'-----------------------------------------------------------
Function SubEnviron(Str As String) As String
Dim pos As Long
Dim strEnv As String
Dim v

SubEnviron = Str
pos = 1
strEnv = Environ(pos)
Do While strEnv < ""
v = Split(strEnv, "=", 2)
v(0) = "%" & v(0) & "%"
SubEnviron = Application.WorksheetFunction.Substitute(SubEnviro n,
v(0), v(1))
pos = pos + 1
strEnv = Environ(pos)
Loop
End Function
'------------------------------------------------------

try it:
msgbox "look for %OS% and %Windir%"

An enhancement could be to add a second optional parameter representing a
filename or registry section to search for instead of the environment
variable table.

Regards,
Sebastien

"kfloyd" wrote:

I've defined some environment variables that I want to use to specify a path
to a directory. How do I use these environment variables in the "Save As"
box?

The variables a

"ADCmath" set to "P:\blah"
"TERM" set to "Fall2004"

I want to save an Excel file in the directory P:\blah\Fall2004 by using
%ADCmath%\%TERM%\filename.xls

but it doesn't work.

(And how can something so simple in UNIX be so obtuse in Windows???)

Ken

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel General Environment Techtrainer Excel Discussion (Misc queries) 1 January 18th 08 12:25 PM
System Environment Variables bdickert Excel Discussion (Misc queries) 1 October 8th 06 08:40 PM
System Environment Variables bdickert Excel Discussion (Misc queries) 9 October 7th 06 09:34 PM
Can excel regognise asp environment? Clogger71 Excel Discussion (Misc queries) 0 July 6th 06 06:24 PM
Can I use Environment variables (such as %USERPROFILE%) in Excel . Tom Ogilvy Excel Programming 0 August 24th 04 04:42 PM


All times are GMT +1. The time now is 07:50 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"