问题描述
我正在VBA for Excel中使用 GetSaveAsFilename
。有没有办法给这个默认文件夹打开?例如,我一直希望它在调用时从 C:\MyDocuments\Music
开始。
I am using GetSaveAsFilename
in VBA for Excel. Is there any way to give this a default folder to open up to? For example, I always want it to start at C:\MyDocuments\Music
when it is called.
推荐答案
FileDialog
对象提供的方式比 GetSaveAsFilename
(及其兄弟 GetOpenFilename
)。示例:
The FileDialog
object offers way more flexibility than GetSaveAsFilename
(and its sibling GetOpenFilename
). Example:
Dim tuneSaver As FileDialog
Set tuneSaver = Application.FileDialog(msoFileDialogSaveAs)
With tuneSaver
.Title = "Save this tune as..."
.InitialFileName = "C:\MyDocuments\Music\"
' Set other properties here...
.Show
End With
请注意,超过256个字符的.InitialFileName
将导致运行时错误。
Note that an .InitialFileName
longer than 256 characters will cause a run-time error.
请参阅。它具有很多有用的特性,包括例如 AllowMultiSelect
(当然,这一点在保存时无关)。
See VBA help on FileDialog
. It has quite a few useful properties, including e.g. AllowMultiSelect
(though admittedly this one is irrelevant when saving).
这篇关于GetSaveAsFilename默认文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!