GetSaveAsFilename默认文件夹 [英] GetSaveAsFilename default folder

查看:294
本文介绍了GetSaveAsFilename默认文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在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.

请参阅 VBA帮助 FileDialog 。它具有很多有用的特性,包括例如 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默认文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆