Filter in msoFileDialogSaveAs

radek225

Registered User.
Local time
Today, 02:42
Joined
Apr 4, 2013
Messages
307
have a function that shows me the saving path choosen by user
The problem is I can't set filter to *accdb. If I work with msoFileDialogFilePicker then .filter property works. What should I do to set filter *accdb in msoFileDialogSaveAs?

Code:
Function Plik(TytulOkna As String, TytulPrzycisku As String, Filtr As String) As String
    Dim wskazMiejsce As FileDialog
    Set wskazMiejsce = Application.FileDialog(msoFileDialogSaveAs)
    wskazMiejsce.Title = TytulOkna
    wskazMiejsce.ButtonName = TytulPrzycisku
    wskazMiejsce.AllowMultiSelect = False
    wskazMiejsce.InitialFileName = "wniosek.accdb"
    If wskazMiejsce.Show = -1 Then
        WskazPlik = wskazMiejsce.SelectedItems(1)
        MsgBox WskazPlik
    End If
End Function
 
.Filters.Add "Images", "*.gif; *.jpg; *.jpeg", 1
 
You can't directly set filters on msoFileDialogSaveAs.
However if you set the InitialFileName to *.accdb then dialog will force that extension. The filter will still say "All Files" but it will not show files with different extensions.
 
You can't directly set filters on msoFileDialogSaveAs.
However if you set the InitialFileName to *.accdb then dialog will force that extension. The filter will still say "All Files" but it will not show files with different extensions.

Why? When you saving some file e.g. from ms office filter is on

you mean wskazMiejsce.InitialFileName = "*.accdb"? - doesn't work. I still see another files
 
you mean wskazMiejsce.InitialFileName = "*.accdb"? - doesn't work. I still see another files

Yes, that. And it works for me, I can see only accdb files and "Save as type" shows "All files (*.*)"
 
My sample is exactly your sample. Only thing I had to do is declare WskazPlik variable as it's not in your function.
Code:
Public Function Plik(TytulOkna As String, TytulPrzycisku As String, Filtr As String) As String
    Dim wskazMiejsce As FileDialog
    Dim WskazPlik As Variant
    Set wskazMiejsce = Application.FileDialog(msoFileDialogSaveAs)
    wskazMiejsce.Title = TytulOkna
    wskazMiejsce.ButtonName = TytulPrzycisku
    wskazMiejsce.AllowMultiSelect = False
    wskazMiejsce.InitialFileName = "*.accdb"
'    wskazMiejsce.Filters.Item(0) = "*.accdb"
    If wskazMiejsce.Show = -1 Then
        WskazPlik = wskazMiejsce.SelectedItems(1)
        MsgBox WskazPlik
    End If
End Function
 
Private Sub Command0_Click()
Dim nazwa As String
    nazwa = Plik("title", "zapisaj", "*.accdb")
End Sub

And as you can see below it shows only accdb files:

savefiledialog.jpg
 

Users who are viewing this thread

Back
Top Bottom