Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XL 07 Get Filtered Filenames in Window 1

Status
Not open for further replies.
Jun 5, 2002
417
AU
Hi,
I have the following macro which lists "*.csv" files for my selection from a specific folder.

Sub CSVOpen()
'
' CSVOpen Macro to Open Window for *.csv files in dir "Super"
' Written PJM 26/2/14
'
Dim myFileName As Variant
Dim Wkbk As Workbook

ChDir "C:\Users\Peter\Documents\Super"
myFileName = Application.GetOpenFilename("Text files, *.csv")

If myFileName = False Then
ChDir "C:\Users\Peter\Documents"
Exit Sub 'user hits Cancel
End If

Workbooks.OpenText Filename:=myFileName 'Open selected file

ChDir "C:\Users\Peter\Documents" 'Reset CurDir to "Documents" for next use.

End Sub

I want to modify it to only display csv files in the window with filenames ending in "abc" eg "15-01Dataabc.csv".

How can I do this in this macro?

Thanks in anticipation,

Peter Moran
 
Make the following change:
Code:
myFileName = Application.GetOpenFilename("Text files, *[COLOR=#EF2929]abc[/color].csv")
 
CAUTION:
When you use.OpenText WITHOUT the optional arguments that can define the data type for each column, you are forcing Excel to ASSUME what they are and can often result in Excel CHANGING your data unwittingly.
 
Hi,

Thanks Guys for the replies.

Skip - have modified the OpenText statement to specify the type of csv after checking it out - thanks!

Zelgar - does not work for me. I had already tried out multiple options of this statement after reading the help file, which did not give any specific indication or example that this would in fact work. I could not get the

("Text Files (*.csv), *.csv")

part of the code to work with the (*.csv) included.

Peter Moran
 
The type of file is one thing, but not the thing that I was referring to.

I'm referring to the data TYPES of each column. Unless you specify otherwise, Excel can chage the DATA!

For instance

6:

Could be changed to

.5

1/2 could change to fourth thousand something; actually, the date serial number of January 2 of the current year.

So I was referring to a spec for every column of data.
 
Hi Skip,

Thanks again for your input.

Your point is taken.

Peter Moran
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top