01-06-2016, 07:50 AM
|
#1
|
Newly Registered User
Join Date: Apr 2013
Posts: 307
Thanks: 75
Thanked 0 Times in 0 Posts
|
Filter in msoFileDialogSaveAs
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
|
|
|
01-06-2016, 08:14 AM
|
#2
|
Newly Registered User
Join Date: Apr 2015
Location: KY,USA
Posts: 3,376
Thanks: 0
Thanked 746 Times in 731 Posts
|
Re: Filter in msoFileDialogSaveAs
.Filters.Add "Images", "*.gif; *.jpg; *.jpeg", 1
|
|
|
01-06-2016, 08:22 AM
|
#3
|
Nieóhfytny jaszczomp
Join Date: Nov 2015
Location: Consett, UK
Posts: 106
Thanks: 5
Thanked 26 Times in 25 Posts
|
Re: Filter in msoFileDialogSaveAs
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.
|
|
|
01-06-2016, 08:40 AM
|
#4
|
Newly Registered User
Join Date: Apr 2013
Posts: 307
Thanks: 75
Thanked 0 Times in 0 Posts
|
Re: Filter in msoFileDialogSaveAs
Quote:
Originally Posted by cyanidem
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
|
|
|
01-06-2016, 08:56 AM
|
#5
|
Nieóhfytny jaszczomp
Join Date: Nov 2015
Location: Consett, UK
Posts: 106
Thanks: 5
Thanked 26 Times in 25 Posts
|
Re: Filter in msoFileDialogSaveAs
Why? Because MS says so here: https://msdn.microsoft.com/en-us/lib...ffice.10).aspx
Quote:
Note A run-time error will occur if the Filters property is used in conjunction with the Clear, Add, or Delete methods when applied to a Save As FileDiaog object. For example, Application.FileDialog(msoFileDialogSaveAs).Filter s.Clear will result in a run-time error.
|
|
|
|
01-06-2016, 09:01 AM
|
#6
|
Newly Registered User
Join Date: Apr 2013
Posts: 307
Thanks: 75
Thanked 0 Times in 0 Posts
|
Re: Filter in msoFileDialogSaveAs
Quote:
Originally Posted by cyanidem
|
Ok, what about InitialFileName, how should i set it correctly to have *accdb?
|
|
|
01-06-2016, 09:01 AM
|
#7
|
Premier Pale Stale Ale
Join Date: Oct 2012
Location: Flint, Michigan, USA
Posts: 3,218
Thanks: 83
Thanked 458 Times in 413 Posts
|
Re: Filter in msoFileDialogSaveAs
__________________
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
|
|
01-07-2016, 03:37 AM
|
#8
|
Nieóhfytny jaszczomp
Join Date: Nov 2015
Location: Consett, UK
Posts: 106
Thanks: 5
Thanked 26 Times in 25 Posts
|
Re: Filter in msoFileDialogSaveAs
Quote:
Originally Posted by radek225
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 (*.*)"
|
|
|
01-07-2016, 11:07 PM
|
#9
|
Newly Registered User
Join Date: Apr 2013
Posts: 307
Thanks: 75
Thanked 0 Times in 0 Posts
|
Re: Filter in msoFileDialogSaveAs
Quote:
Originally Posted by cyanidem
Yes, that. And it works for me, I can see only accdb files and "Save as type" shows "All files (*.*)"
|
Could you show me your sample?
|
|
|
01-08-2016, 01:01 AM
|
#10
|
Nieóhfytny jaszczomp
Join Date: Nov 2015
Location: Consett, UK
Posts: 106
Thanks: 5
Thanked 26 Times in 25 Posts
|
Re: Filter in msoFileDialogSaveAs
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
|
|
|
Thread Tools |
|
Display Modes |
Rate This Thread |
Linear Mode
|
|
All times are GMT -8. The time now is 10:54 PM.
|
|