在 VBA Excel 2003 中获取“我的文档”文件夹的语言独立方式

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7751464/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 14:15:48  来源:igfitidea点击:

Language independent way to get "My Documents" folder in VBA Excel 2003

excelvbaexcel-2003

提问by Diego Castro

I need a Language independent way to get "My Documents" folder in VBA Excel 2003.

我需要一种独立于语言的方式来获取 VBA Excel 2003 中的“我的文档”文件夹。

What I have:

我拥有的:

Public Function MyDocsPath() As String
    MyDocsPath = Environ$("USERPROFILE") & "\My Documents\"
End Function

Because the program will be used in at least 2 lang MS Windows, and the "My Documents" name changes for each language.

因为该程序将在至少 2 语言的 MS Windows 中使用,并且“我的文档”名称随每种语言而变化。

Is there a way, or should I try to figure out the system lang and become specific?

有没有办法,或者我应该尝试找出系统语言并变得具体?

回答by Fionnuala

This may suit:

这可能适合:

Set WshShell = CreateObject("WScript.Shell")
strDocuments = WshShell.SpecialFolders("MyDocuments")

From: http://msdn.microsoft.com/en-us/library/0ea7b5xe.aspx

来自:http: //msdn.microsoft.com/en-us/library/0ea7b5xe.aspx

Although the special folder name is MyDocuments, it refers to the documents folder for several versions of Windows.

尽管特殊文件夹名称是 MyDocuments,但它指的是多个 Windows 版本的文档文件夹。