use a wild card to find a file

rhino4eva

Board Regular
Joined
Apr 1, 2009
Messages
234
fname = Application.GetOpenFilename(filefilter:="txt Files (*.txt),*.txt")

I use the code above to select a txt file to import into excel
however the directory that this file is located is full of junk that I'm not bothered about
how can I modify the "*" to show only "any file that has the string TCTB" in it and not show the junk
 

Some videos you may like

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.

Yongle

Well-known Member
Joined
Mar 11, 2015
Messages
6,744
Office Version
  1. 365
Platform
  1. Windows
try this instead
- remember the final path separator

Code:
Sub TextFile()
    Dim fName As String, p As String
    p = "C:\test\subfolder[SIZE=3][COLOR=#ff0000]\[/COLOR][/SIZE]"
    With Application.FileDialog(msoFileDialogFilePicker)
        .InitialFileName = p & "*TCTB*.txt"
        .AllowMultiSelect = False
        .Show
        If .SelectedItems.Count > 0 Then fName = .SelectedItems(1)
    End With
    MsgBox fName
End Sub
 

Yongle

Well-known Member
Joined
Mar 11, 2015
Messages
6,744
Office Version
  1. 365
Platform
  1. Windows
thanks for your feedback
(y)
 

Watch MrExcel Video

Forum statistics

Threads
1,108,969
Messages
5,525,961
Members
409,673
Latest member
Riseee

This Week's Hot Topics

Top