问题
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