Excel/VBA Environ(“用户名")错误 [英] Excel/VBA Environ("username") error

查看:129
本文介绍了Excel/VBA Environ(“用户名")错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个电子表格,其中包含一系列模型输入,这些模型输入已加载到SQL Server数据库中.此过程的一部分涉及构建审核跟踪记录,以了解谁更新了什么内容和时间-我记录了用户名和计算机名以及时间戳.

I have a spreadsheet that contains a range of model inputs that get loaded into a SQL Server database. Part of this process involves building an audit trail of who updated what and when - I record the user and machine name as well as timestamp.

在我的VBA代码中,我有以下内容:

Within my VBA code, I have the following:

user = VBA.environ $(用户名")

user = VBA.environ$("username")

它在带有Office 2013的Win7计算机上运行.

This is running on a Win7 machine, with Office 2013.

当我运行代码时,一切正常,但是当生产中的某个人运行它(在同一台计算机上,但他们登录的是我(不是我))时,它落在了上面的行上.我使用了上面的变体(用户= environ(用户名"),用户= environ $(用户名")),但总是得到相同的结果-它对我有用,但对其他人不起作用.

When I run the code, it all works fine, but when someone in production runs it (on the same machine, but they are logged in, not me), it falls over on the line above. I have used variations of the above (user = environ("username"), user = environ$("username")) but always with the same outcome - it works for me, but not for others.

有人对如何解决此问题有任何想法吗?

Does anyone have any thoughts on how to fix this?

推荐答案

您在这里:

Sub Test()
    With CreateObject("WScript.Network")
        Debug.Print .UserName
        Debug.Print .ComputerName
        Debug.Print .UserDomain
    End With
End Sub

这篇关于Excel/VBA Environ(“用户名")错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆