C
ChristopherL
My question is on the subject line.
Thank You
Chris
Thank You
Chris
Says here there's an Environ function you can use, eg vx = Environ("PATH").
- Show quoted text -
Sorry, I need to clarify my question. I did not want to determine the
contents of an environment variable! What I want to do is be able to
go out to the "command prompt" and set an arbitrary environment
variable.
I tried the following, but VBA tells me the path to the command was
not found:
dim ev_result as string
en_result = shell ("""set chris=1 2 3""")
The 3 sets of double quotes is to try to simulate doing the following
in a command prompt window: set chris="1 2 3".
Again, I want to set an environment variable within VBA.
Ah, right you are; I misread the question, reversing the subject and
predicate. Ok, I know I've run across this somewhere; I think it's a
property of one of those COM objects like wscript or WSH or something.
...Ah, here it is. Well, maybe it is. Try this:
Set ows = WScript.CreateObject("WScript.Shell")
Set oEnv = ows.Environment("SYSTEM")
oEnv("PATH") = oEnv("PATH") & ";c:\Utils"
I got this sequence fromhttp://msdn.microsoft.com/en-us/library/6s7w15a0(VS.85).aspx, except it
mentions only display without saying whether you can also change the
environment variable. Give it a try; maybe it'll work.
- Show quoted text -
The environment variable would be alive as long as the Shell is alive--but it's
limited to that shell and its children.
So if you need to run a .bat file that needs an environment variable, youcould
shell to a different .bat file that sets the environment variable and then runs
the .bat file that you need to run.
But if you want to change the environment variable globally, it's a different
story.
Win95 came with command called WinSet that did this. But I don't see it in
WinXP (at least in a normal install).
But you could search google looking for alternatives.
I've never used this, but it looks interesting:http://www.codeguru.com/cpp/w-p/win32/tutorials/article.php/c10849/
....
Dave Peterson- Hide quoted text -
- Show quoted text -
I don't understand what this:
ev_result = Wait_("cmd /k set chris=""1 2 3"" & %chris%", "", False, True)
is doing.
And I don't understand what you're really trying to do.
Are you trying to create an environment variable that's available for just the
duration of that Shell command--and only available to the that Shell?
Or are you trying to create an environment variable that can be seen by
anything?
--
Dave Peterson- Hide quoted text -
- Show quoted text -
And I don't understand what you're really trying to do.
Are you trying to create an environment variable that's available for just the
duration of that Shell command--and only available to the that Shell?
Or are you trying to create an environment variable that can be seen by
anything?
But if you want to change the environment variable globally, it's a different
story.
Dave and every one, I have to be able to change the environment
variable globally.
Chris
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.