所以我们有一个要求用户登录的系统,它有自己的漫游配置文件。那么在这串代码中,我如何定位当前用户的文件夹? (仅供引用Excel 2010)
'WORKAROUND:
Dim PID As Double
Dim strRootPath As String
Const strExpExe = "explorer.exe"
Const strArg = " " '" /e,/root, "
'this is where i need to figure out how to target current user's documents
'// Change rootpath here
strRootPath = "C:\Data Files"
PID = Shell(strExpExe & strArg & strRootPath, 3)
该功能的其余部分做得很好......它打开文件资源管理器我只是想不出告诉它寻找当前用户的语法。
最佳答案
可能最好的方法是使用这样的函数:
Function docsFolder() As String
docsFolder = CreateObject("WScript.Shell").SpecialFolders("MyDocuments")
End Function
还有其他方法,但这种方法适用于任何版本的 Windows 并具有用户自定义。
例如,就我而言,我的文档文件夹位于映射的
X:
上。驱动器,所以只需将我的用户名填入 C:\
路径行不通。更多信息:
SpecialFolders
Property 关于vba - 一个目标怎么可能是当前用户的文档文件夹?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51803784/