Environ Function code samples for VBA

前端 未结 3 1559
死守一世寂寞
死守一世寂寞 2020-11-30 04:54

I am looking for some information or code samples for the Environ Function in VBA to grab the username on the current system.

3条回答
  •  -上瘾入骨i
    2020-11-30 05:31

    Environ() gets you the value of any environment variable. These can be found by doing the following command in the Command Prompt:

    set
    

    If you wanted to get the username, you would do:

    Environ("username")
    

    If you wanted to get the fully qualified name, you would do:

    Environ("userdomain") & "\" & Environ("username")
    

    References

    • Microsoft | Office VBA Reference | Language Reference VBA | Environ Function
    • Microsoft | Office Support | Environ Function

提交回复
热议问题