Filter in msoFileDialogSaveAs (1 Viewer)

radek225

Registered User.
Local time
Today, 10:54
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
 

Ranman256

Registered User.
Local time
Today, 13:54
Joined
Apr 9, 2015
Messages
3,480
.Filters.Add "Images", "*.gif; *.jpg; *.jpeg", 1
 

cyanidem

Nieóhfytny jaszczomp
Local time
Today, 18:54
Joined
Nov 30, 2015
Messages
106
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.
 

radek225

Registered User.
Local time
Today, 10:54
Joined
Apr 4, 2013
Messages
307
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
 

cyanidem

Nieóhfytny jaszczomp
Local time
Today, 18:54
Joined
Nov 30, 2015
Messages
106
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 (*.*)"
 

cyanidem

Nieóhfytny jaszczomp
Local time
Today, 18:54
Joined
Nov 30, 2015
Messages
106
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 (Users: 0, Guests: 1)

Top Bottom