
querying environment variables from vba
Hi DCurren,
Yep, this will work on a Microsoft network, but isn't guaranteed on other
network types:
Sub ShowUserName()
Dim uname As String
uname = Environ("USERNAME")
MsgBox uname
End Sub
Check the Help topic on the Environ function. It doesn't work at all on a
Macintosh.
--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://www.mvps.org/word
Quote:
> Thanks a lot - that worked with just a little modification.
> I would never have figured that out on my own. I even
> looked around on the mvps site but did not use the proper
> search terms.
> Although this works fine for the present macro, it would
> probably come in handy later - is there a way to query the
> environment variables?
>> -----Original Message-----
>> Hi DCurren,
>> See the article "How to get the username of the current user" at:
>> http://www.mvps.org/word/FAQs/MacrosVBA/GetCurUserName.htm
>> Please respond to the newsgroups for the benefit of
> others who may be
>> interested.
>> Hope this helps
>> Doug Robbins - Word MVP
>>> Hello All,
>>> Can someone please tell me if it's possible to query an
>>> environment variable for use in a macro? If I have a cmd
>>> prompt open and type set, I get list of all the env.
>>> variables. I see the environment variable
>>> called "UserName" is set to BBJohnson and it would be such
>>> a huge improvement to my macro if I could get that
>>> information from that variable.
>> .