问题
I just need to get the name of the current user so I can access the app data folder within their folders.... I have to do this in VBA so yeah...help please.
回答1:
I believe it's something like
Environ("Username")
回答2:
You do not need user name to know which folder is app data folder.
You need to use the SHGetFolderPath function with the CSIDL_APPDATA
value.
Private Declare Function SHGetFolderPath Lib "shell32.dll" Alias "SHGetFolderPathA" (ByVal hwnd As Long, ByVal csidl As Long, ByVal hToken As Long, ByVal dwFlags As Long, ByVal pszPath As String) As Long
Private Const CSIDL_APPDATA As Long = &H1A
Private Const MAX_PATH As Long = 260
Dim s As String
s = String$(MAX_PATH, 0)
SHGetFolderPath 0, CSIDL_APPDATA, 0, 0, s
MsgBox Left$(s, InStr(1, s, vbNullChar))
来源:https://stackoverflow.com/questions/6255535/how-do-i-get-the-current-user-name-in-vba