ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Any way to grab a .csv file from a folder using Wildcards (https://www.excelbanter.com/excel-programming/272235-any-way-grab-csv-file-folder-using-wildcards.html)

David Johnston

Any way to grab a .csv file from a folder using Wildcards
 
Does anyone know of a way that I can grab a .csv file out of a local
folder with out specifying the exact document. I have created a macro
that can take the CSV data and import into the Excel worksheet save it
and print it but only if I code it to that exact CSV document. I was
hoping to be able to just have it grab any CSV document in a
particular folder. There will be only one CSV document at anytime in
the folder but it will not always be named the same. Any ideas.

Dan E[_2_]

Any way to grab a .csv file from a folder using Wildcards
 
David,

You can use
inFile = Application.GetOpenFilename
which will open a standard "Open" file dialog box to browse for your .csv
file and returns a file name and path
ie (inFile = "C:\My Documents\MyCSV.csv")

Dan E

"David Johnston" wrote in message
om...
Does anyone know of a way that I can grab a .csv file out of a local
folder with out specifying the exact document. I have created a macro
that can take the CSV data and import into the Excel worksheet save it
and print it but only if I code it to that exact CSV document. I was
hoping to be able to just have it grab any CSV document in a
particular folder. There will be only one CSV document at anytime in
the folder but it will not always be named the same. Any ideas.




Dan E[_2_]

Any way to grab a .csv file from a folder using Wildcards
 
Here's another option,

This one has a fixed folder to look for the csv file in

Private Sub CommandButton1_Click()
On Error GoTo Endit
Dim fs, f, f1, fc, s
folderspec = "C:\My Documents"
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder(folderspec)
Set fc = f.Files
i = 0
For Each f1 In fc
If Right(f1.Name, 3) = "csv" Then
inFileName = f1.ParentFolder.Path & "\" & f1.Name
i = i + 1
End If
Next
ret = MsgBox(i & " CSV file(s) found ," & inFileName & " used",
vbOKOnly)

Endit:
If i = 0 Then
ret = MsgBox("No CSV file Found", vbOKOnly, "Bad Input")
End If
End Sub

Dan E

"David Johnston" wrote in message
om...
Does anyone know of a way that I can grab a .csv file out of a local
folder with out specifying the exact document. I have created a macro
that can take the CSV data and import into the Excel worksheet save it
and print it but only if I code it to that exact CSV document. I was
hoping to be able to just have it grab any CSV document in a
particular folder. There will be only one CSV document at anytime in
the folder but it will not always be named the same. Any ideas.




Lynn Schauer

Any way to grab a .csv file from a folder using Wildcards
 
if there is only one csv file in the directory, try the following

f=dir("c:\my folder\*.csv")

at this point f will be the filename including the path,

Lynn S
"David Johnston" wrote in message
om...
Does anyone know of a way that I can grab a .csv file out of a local
folder with out specifying the exact document. I have created a macro
that can take the CSV data and import into the Excel worksheet save it
and print it but only if I code it to that exact CSV document. I was
hoping to be able to just have it grab any CSV document in a
particular folder. There will be only one CSV document at anytime in
the folder but it will not always be named the same. Any ideas.





All times are GMT +1. The time now is 11:57 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com