VBA Get Username on OSX (or Mac alternative to Environ(“username”))

前端 未结 2 420
走了就别回头了
走了就别回头了 2020-12-20 20:44

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 Windo

相关标签:
2条回答
  • 2020-12-20 21:01

    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
    
    0 讨论(0)
  • 2020-12-20 21:16

    Environ("USER") and Environ("LOGNAME") return the same thing on the Mac as the MacScript answer.

    0 讨论(0)
提交回复
热议问题