Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login




Remember Me
Forgot Password?
Join Us!

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.
Jobs from Indeed

Link To This Forum!

Partner Button
Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

VBA Visual Basic for Applications (Microsoft) FAQ

Office / VBA General

List environment variables
Posted: 13 Oct 03

This FAQ is simply some code to show all the current environment variables for the current excel session. Environment variables can be used to test for users, homedrives, no. of processors and domains amoungst other things. It works on windows only (sorry mac users) and I use it most often to obtain the network userid of the current user. This is especially useful where you have different types of access depending on who the user is.

This code will show all the environment variables:

Sub List_Environment_Variables()
Dim EnvString As String
Indx = 1
Do
    EnvString = Environ(Indx)
    Cells(Indx, 1) = EnvString
    Indx = Indx + 1
Loop Until EnvString = ""
End Sub


The one I use most is
environ("username")

so you can use

dim myUser as string
myUser = environ("username")

to return the current user's network id

Back to VBA Visual Basic for Applications (Microsoft) FAQ Index
Back to VBA Visual Basic for Applications (Microsoft) Forum

My Archive

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close