MS Office SaveAs type FileDialog with a filter in vb

旧时模样 提交于 2019-12-23 11:59:06

问题


I want to create a 'save as' file dialog with a filter, but this doesn't seem possible using the FileDialog class (Microsoft Office 12.0 Object Library). The documentation actually mentions this here, see last paragraph, but gives no reason as to why? Is there another way of achieving this in vb?

I find it strange that the FileDialog class doesn't allow this because Word, Excel and Access all have this exact SaveAs feature built-in.

I realise that the FileDialog can created as a FilePicker (msoFileDialogFilePicker) which does allow filters, but then this doesn't allow a file to be selected that doesn't yet exist, which defeats the whole point.


回答1:


That appears to be a restriction of that particular class for some reason, so how about;

Dim vResult As Variant
vResult = Application.GetSaveAsFilename("default.blah", "blah files,*.blah,Text file,*.txt,All files,*.*", 0, "Title")
If VarType(vResult) = vbBoolean Then
    MsgBox "cancelled"
Else
    MsgBox vResult
End If



回答2:


As @AlexK mentioned the only way to do this is using a windows API call. See here



来源:https://stackoverflow.com/questions/5881105/ms-office-saveas-type-filedialog-with-a-filter-in-vb

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!