Later, as usual, but hopefully a better solution ...
Public Function GetSaveFilename() As String Dim Dialog As FileDialog: Set Dialog = Application.FileDialog(msoFileDialogSaveAs) With Dialog .InitialFileName = CurrentProject.Path & "\*.ext" .FilterIndex = 2 .Title = "Save As" If .Show <> 0 Then GetSaveFilename = .SelectedItems(1) End If End With End Function
How it works?
As is well known, you can not directly set filters on msoFileDialogSaveAs. However, if you set the InitialFileName to "* .ext", this will force this extension. The filter will still say โAll files,โ however it will not show files if they donโt have the extension you provided.
Result

If you delete "* .ext" and just write "test", for example, the resulting file name will be "test.ext", so it actually forces this extension.
This is not ideal, but very simple and achieves the desired result without resorting to API calls for those who are less experienced with code.
Warning
This only works for one extension at a time, for example. "* .csv". If you need to filter out several extensions, for example. images, then you have to resort to using API calls.
Dave williams
source share