【发布时间】:2016-06-25 01:51:31
【问题描述】:
我有从 Excel VBA 中生成 GMail 电子邮件的代码,但是,我正在寻找可以确定当前用户是谁并返回当前用户的 Gmail 电子邮件地址的代码。
【问题讨论】:
-
确定当前用户是谁?电脑用户?还是当前登录 gmail 的人?
我有从 Excel VBA 中生成 GMail 电子邮件的代码,但是,我正在寻找可以确定当前用户是谁并返回当前用户的 Gmail 电子邮件地址的代码。
【问题讨论】:
我不知道是否有办法从代码中获取 GMAIL 地址,除非他们的 GMAIL 帐户打开了浏览器窗口
获取当前用户名的微软示例代码
' Makes sure all variables are dimensioned in each subroutine.
Option Explicit
' Access the GetUserNameA function in advapi32.dll and
' call the function GetUserName.
Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" _
(ByVal lpBuffer As String, nSize As Long) As Long
' Main routine to Dimension variables, retrieve user name
' and display answer.
Sub Get_User_Name()
' Dimension variables
Dim lpBuff As String * 25
Dim ret As Long, UserName As String
' Get the user name minus any trailing spaces found in the name.
ret = GetUserName(lpBuff, 25)
UserName = Left(lpBuff, InStr(lpBuff, Chr(0)) - 1)
' Display the User Name
MsgBox UserName
End Sub
【讨论】:
UserName = ENVIRON("username") 是获取用户名的更简单方法:)