VBA Application.GetOpenFilename for exact file name

rpaulson

Well-known Member
Joined
Oct 4, 2007
Messages
1,414
here is my code.

Code:
Sub Restore_Setup()
  Dim Finfo As String
  Dim FilterIndex As Long
  Dim Title As String
  Dim FileName As Variant

  Finfo = "Text Files (*.txt),*.txt,"
  Title = "Select a SETUP to Import"

  FileName = Application.GetOpenFilename(Finfo, _
    FilterIndex, Title)

  If FileName = False Then exit sub

.... more code


the above code will allow the user to select any *.txt file.

I wish to only allow the user to see and only select setup*.txt files.
I tried this:
Finfo = "Text Files (setup*.txt),setup*.txt,"
but no luck

any ideas?

ross
 
Last edited:

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
See if this helps you any...
Code:
[table="width: 500"]
[tr]
	[td]Sub Test()
  Dim Result As Long, WildcardPathFilter As String, Path As String, FileName As String
  
  [B][COLOR="#008000"]' Note the path is specified along with the wildcard name filter[/COLOR][/B]
  WildcardPathFilter = "c:\temp\setup*.txt"
  
  With Application.FileDialog(msoFileDialogFilePicker)
    .Title = "Select Test File"
    .Filters.Add "Text File", "*.txt"
    .FilterIndex = 1
    .AllowMultiSelect = False
    .InitialFileName = WildcardPathFilter
    Result = .Show
    
    If (Result <> 0) Then
      [B][COLOR="#008000"]' A name was selected... put your code to handle it here[/COLOR][/B]
      MsgBox "Selected Filename: " & Trim(.SelectedItems.Item(1))
    End If
    
  End With
End Sub[/td]
[/tr]
[/table]
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,259
Members
452,626
Latest member
huntinghunter

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