Save with msoFileDialogFilePicker

I have searched this topic many times, and I have tried a lot. In fact, I need to ask the user to save as a user type that is not available in msoFileDialogSaveAs filters.

I know that I can save, say, *.txt , and then change the extension before saving. I did this, and it worked, but when the user enters the file name into a folder that already contains other files of a custom type, the user will not see a list of existing user files, because the active filter is not of this type.

So I was wondering if it is possible to use msoFileDialogFilePicker to save as a custom type by entering the file name.

Here's what it might look like:

 Function userFileSaveDialog_OneFilterOnly(iFilter As String, _ iExtension As String, _ Optional iTitle As String) With Application.FileDialog(msoFileDialogFilePicker) '(msoFileDialogSaveAs) .Filters.Clear .Filters.Add iFilter, iExtension .AllowMultiSelect=False .ButtonName "Save" .Title = iTitle If CBool(.Show) Then userFileSaveDialog_OneFilterOnly = .SelectedItems(.SelectedItems.Count) Else End If End With End Function 

Thanks for the help!

+5
excel-vba excel
source share
1 answer

As I mentioned in the comments, you can use Application.GetSaveAsFilename

Syntax

expression.GetSaveAsFilename(InitialFilename, FileFilter, FilterIndex, Title, ButtonText)

And here is a usage example

 Sub Sample() Dim Ret Ret = userFileSaveDialog_OneFilterOnly("My Special Files", "Sid", "An Example") MsgBox Ret End Sub Function userFileSaveDialog_OneFilterOnly(iFilter As String, _ iExtension As String, _ Optional iTitle As String) Dim Ret Ret = Application.GetSaveAsFilename(fileFilter:=iFilter & _ " (*." & _ iExtension & _ "), *." & iExtension, _ Title:=iTitle) If Ret <> False Then userFileSaveDialog_OneFilterOnly = Ret End Function 

In action

enter image description here

+3
source share

All Articles