我需要一种语言无关的方法来在VBA Excel 2003中获取“我的文档”文件夹。
我的代码:
Public Function MyDocsPath() As String
MyDocsPath = Environ$("USERPROFILE") & "\My Documents\"
End Function
因为该程序将在至少2种语言的MS Windows中使用,而“My Documents”名称会因每种语言而异。是否有一种方法,或者我应该尝试确定系统语言并变得更加具体?
我需要一种语言无关的方法来在VBA Excel 2003中获取“我的文档”文件夹。
我的代码:
Public Function MyDocsPath() As String
MyDocsPath = Environ$("USERPROFILE") & "\My Documents\"
End Function
因为该程序将在至少2种语言的MS Windows中使用,而“My Documents”名称会因每种语言而异。这可能适合:
Set WshShell = CreateObject("WScript.Shell")
strDocuments = WshShell.SpecialFolders("MyDocuments")
来源: http://msdn.microsoft.com/zh-cn/library/0ea7b5xe.aspx
虽然特殊文件夹名称为“我的文档”,但它实际上指的是多个 Windows 版本中的文档文件夹。
' Application.PathSeparator can be used, but this
' is unlikely to work on non-Windows environments
MyDocsPath = Environ$("USERPROFILE") & "\Documents\"
考虑到这是一个十年前的问题,那时可能不是这样的。 :)