Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default How do I set an environment variable to a string

My question is on the subject line.

Thank You
Chris
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default How do I set an environment variable to a string

We need more info than that. What exactly are you wanting to do...

dim str as string

str = environ("userName")
msgbox str

--
HTH...

Jim Thomlinson


"ChristopherL" wrote:

My question is on the subject line.

Thank You
Chris

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 108
Default How do I set an environment variable to a string

Says here there's an Environ function you can use, eg vx = Environ("PATH").

--- "ChristopherL" wrote:
How do I set an environment variable to a string

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default How do I set an environment variable to a string

On Aug 12, 6:10*pm, Bob Bridges
wrote:
Says here there's an Environ function you can use, eg vx = Environ("PATH").



--- "ChristopherL" wrote:
How do I set an environment variable to a string- Hide quoted text -


- 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.

Thank you,
Chris
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default How do I set an environment variable to a string

On Aug 13, 12:12*am, ChristopherL wrote:
On Aug 12, 6:10*pm, Bob Bridges
wrote:

Says here there's an Environ function you can use, eg vx = Environ("PATH").


--- "ChristopherL" wrote:
How do I set an environment variable to a string- Hide quoted text -


- 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.


Sorry again, I think I have a partial solution, if not a complete
solution! I'll try it tomorrow. Please critique me

dim ev_result as string

ev_result = shell ("\cmd ""set chris=1 2 3""")

en_result = Environ ("chris")
'en_result should be "1 2 3"

Thank you everyone in VBA land,
Chris



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 108
Default How do I set an environment variable to a string

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 from
http://msdn.microsoft.com/en-us/libr...a0(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.

--- "ChristopherL" wrote:
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".


On Aug 12, 6:10 pm, Bob Bridges
wrote:
Says here there's an Environ function you can use, eg vx = Environ("PATH").


--- "ChristopherL" wrote:
How do I set an environment variable to a string- Hide quoted text -

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
using environment variable in macropath M. Mix Excel Programming 5 February 14th 07 08:26 PM
Environment Variable Names Chaplain Doug Excel Programming 3 April 20th 06 03:33 PM
Can you set a Window's Environment variable in VB Ken Soenen Excel Programming 3 March 12th 06 06:19 PM
Environment Variable Andibevan[_4_] Excel Programming 5 August 3rd 05 02:17 PM
How can I invoke windows environment variable in excel Bert van den Brink Excel Programming 0 August 6th 03 08:46 PM


All times are GMT +1. The time now is 09:10 PM.

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

About Us

"It's about Microsoft Excel"