vba - 一个目标怎么可能是当前用户的文档文件夹?

标签 vba excel exacttarget file-location

所以我们有一个要求用户登录的系统,它有自己的漫游配置文件。那么在这串代码中,我如何定位当前用户的文件夹? (仅供引用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:\路径行不通。

更多信息:
  • 堆栈溢出:Language independent way to get “My Documents” folder in VBA
  • 微软技术网:What is the path to My Documents?
  • MSDN : Wshell: SpecialFolders Property
  • 关于vba - 一个目标怎么可能是当前用户的文档文件夹?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51803784/

    相关文章:

    VBA Combobox 和 Listbox 通用父类(super class)

    excel - 如何获取Excel单元格的 "Name Box"名称?

    excel - 验证列表自动将字符串转换为VBA中的日期

    java - 如何通过 Apache POI 使用公式从 Excel 检索日期

    vba - Excel VBA中的列类型转换

    if-statement - AMPScript 中的 IF 语句

    vba - 用于编辑页眉和页脚的 WORD 2010 宏

    Python Pandas 导出数据

    javascript - 将 AMPScript(ExactTarget 脚本语言)变量分配给我的 DOM 上的字段值?

    exacttarget - AMPSCRIPT - 使用 for 循环构建字符串