VBA在OSX(或Mac的替代环境(“用户名”))上获取用户名 [英] VBA Get Username on OSX (or Mac alternative to Environ("username"))

查看:304
本文介绍了VBA在OSX(或Mac的替代环境(“用户名”))上获取用户名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的任务是创建一个安全的(Windows版本)Excel工作簿,它使用宏来验证用户是否有权限查看内容。在Excel 2010 for Windows中,我使用 Environ(username)函数来完成此操作。



问题我遇到的是,组织中的一些用户使用Mac进行日常工作,而 Environ 不适用于OSX。有没有人知道可以找到Mac用户名的替代方式?我已经上网了,但我可以找到的是如何找到计算机的唯一标识符,而不是用户名。



我正在尝试甚至可以使用Mac?



任何信息不胜感激! p>

解决方案

您可以使用AppleScript返回用户名,并从VBA中运行该用户名。



以下功能应该做到这一点。

  Function GetUserNameMac )As String 
Dim sMyScript As String

sMyScript =将用户名设置为(系统信息)的短用户名& vbNewLine& return userName

GetUserNameMac = MacScript(sMyScript)
结束函数


My task has been to create a secure (Windows version) Excel workbook that uses macros to validate whether a user has permission to view the contents. In Excel 2010 for Windows, I use the Environ("username") function to accomplish this.

The problem I'm running into is that some users in the organization use a Mac to do their daily work, and Environ does not work with OSX.

Does anyone know of an alternate way to find the username of a Mac? I've looked online but all I can find is how to find the unique identifier of the computer, not the username.

Is what I'm attempting to do even possible with Mac?

Any information is appreciated!

解决方案

You can use AppleScript to return the Username and run that from VBA.

The following function should do the trick.

Function GetUserNameMac() As String
    Dim sMyScript As String

    sMyScript = "set userName to short user name of (system info)" & vbNewLine & "return userName"

    GetUserNameMac = MacScript(sMyScript)
End Function

这篇关于VBA在OSX(或Mac的替代环境(“用户名”))上获取用户名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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