vba UserName = Environ$("UserName") 在最新版本的 Windows 中不起作用?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17089348/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 21:37:29  来源:igfitidea点击:

UserName = Environ$("UserName") not working in latest versions of Windows?

excel-vbavbaexcel

提问by user1717622

This code does not appear to work in Windows 7/8?

此代码在 Windows 7/8 中似乎不起作用?

Public Function UserName()
    UserName = Environ$("UserName")
End Function

Is there a hack for this?

有没有黑客?

Regards,

问候,

回答by Grant

I use:

我用:

Username = CreateObject("WScript.Network").Username

回答by Ripster

This works for me on Windows7 using Excel 2010.

这对我在 Windows7 上使用 Excel 2010 有效。

Environ("username")

UserNameUserName2

用户名用户名2