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.
我只需要获取当前用户的名称,这样我就可以访问他们文件夹中的应用程序数据文件夹....我必须在VBA中这样做,所以是的...请帮助。
2 个解决方案
#1
7
I believe it's something like
我相信它就像是
Environ("Username")
#2
9
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.
您需要将SHGetFolderPath函数与CSIDL_APPDATA值一起使用。
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))
#1
7
I believe it's something like
我相信它就像是
Environ("Username")
#2
9
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.
您需要将SHGetFolderPath函数与CSIDL_APPDATA值一起使用。
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))