Application.GetOpenFilename(FileFilter: Question

phxsportz

Well-known Member
Joined
Jun 11, 2006
Messages
1,985
I have code that allows the user to choose a Picture File to associate with a given record. The question I have is.. is there a way to choose mutliple file types in the FileFilter option ?

I've scoured the web for a breakdown on the proper syntax and can't seem to locate it anywhere.

Here's the code
Code:
Private Sub bt_browse_Click()
    ' Allows user to browse the computer for a picture file to be displayed
    ' While this file can reside anywhere it will be necessary for it to be present
    ' in the specified image directory that was entered in the Setup Worksheet
    Dim FName As Variant
    FName = Application.GetOpenFilename(FileFilter:="Pictures,*.jpg", Title:="Select a Picture", MultiSelect:=False)
    If FName <> False Then
        img_Liquor.Picture = LoadPicture(FName)
        tb_image = LTrim(Mid(FName, 1 + InStrRev(FName, "\")))
    End If

End Sub
What I would like to do is let them choose JPG's, but also include the option of choosing a .GIF as well..

Thanks for any help...
 
Last edited:
Try the below code...

Code:
Private Sub bt_browse_Click()
    ' Allows user to browse the computer for a picture file to be displayed
    ' While this file can reside anywhere it will be necessary for it to be present
    ' in the specified image directory that was entered in the Setup Worksheet
    Dim FName As Variant
    FName = Application.GetOpenFilename(FileFilter:="Pictures, *.jpg; *.gif", Title:="Select a Picture", MultiSelect:=False)
    If FName <> False Then
        img_Liquor.Picture = LoadPicture(FName)
        tb_image = LTrim(Mid(FName, 1 + InStrRev(FName, "\")))
    End If

End Sub

HTH
Ilyas Kazi
 
Upvote 0
Greetings,

Maybe similar to:

<font face=Courier New>    x = Application.GetOpenFilename( _<br>        FileFilter:="Picture Files (*.gif;*.jpg;*.jpeg;*.bmp),*.gif;*.jpg;*.jpeg;*.bmp", _<br>        Title:="Select Picture")<br>            </FONT>

Hope this helps,

Mark
 
Upvote 0
Hi, Please refer VBA help on GetOpenFilename. Extend FileFilter. HTH, Fazza

GetOpenFilename Method

See AlsoApplies ToExampleSpecifics

Displays the standard Open dialog box and gets a file name from the user without actually opening any files.
expression.GetOpenFilename(FileFilter, FilterIndex, Title, ButtonText, MultiSelect)
expression Required. An expression that returns an Application object.


FileFilter Optional Variant. A string specifying file filtering criteria.
This string consists of pairs of file filter strings followed by the MS-DOS wildcard file filter specification, with each part and each pair separated by commas. Each separate pair is listed in the Files of type drop-down list box. For example, the following string specifies two file filters<NBSP />— text and addin: "Text Files (*.txt),*.txt,Add-In Files (*.xla),*.xla".

To use multiple MS-DOS wildcard expressions for a single file filter type, separate the wildcard expressions with semicolons; for example, "Visual Basic Files (*.bas; *.txt),*.bas;*.txt".

If omitted, this argument defaults to "All Files (*.*),*.*".


FilterIndex Optional Variant. Specifies the index numbers of the default file filtering criteria, from 1 to the number of filters specified in FileFilter. If this argument is omitted or greater than the number of filters present, the first file filter is used.


Title Optional Variant. Specifies the title of the dialog box. If this argument is omitted, the title is "Open."


ButtonText Optional Variant. Macintosh only.


MultiSelect Optional Variant. True to allow multiple file names to be selected. False to allow only one file name to be selected. The default value is False

Remarks

This method returns the selected file name or the name entered by the user. The returned name may include a path specification. If MultiSelect is True, the return value is an array of the selected file names (even if only one filename is selected). Returns False if the user cancels the dialog box.
This method may change the current drive or folder.

Example

This example displays the Open dialog box, with the file filter set to text files. If the user chooses a file name, the code displays that file name in a message box.


<CODE>
Rich (BB code):
fileToOpen = Application _</CODE>
<CODE>.GetOpenFilename("Text Files (*.txt), *.txt")</CODE>
<CODE>If fileToOpen <> False Then</CODE>
<CODE>MsgBox "Open " & fileToOpen</CODE>
<CODE>End If
</CODE>








</PRE>
 
Upvote 0
Thanks to both of you on this one... Not sure why my VBA Help didn't produce what you displayed.. perhaps I need to do a clean install of office..

Thanks again

John
 
Upvote 0
Hello,
Using ur code i could get multiple Filenames. I need to traverse through the list. and i need do it in a loop how will i do it? how will i get count and each value one by one?
 
Upvote 0

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top