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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open CSV file

Status
Not open for further replies.

lleal

Technical User
Sep 13, 2007
1
US
I'm trying to write a marco to summarize test data. I receive the test data in multiple CSV files. I need to place everything into one workbook. I have a macro that will open all the CSV files and place them onto a single workbook but then I'm unable to get the code to work so that I'm able to populate a single chart with data from each sheet because the sheet names are dependant on the CSV file name.

I'm thinking it may be easier to get a macro to work for one file and then create a loop to get the additional files, but the line below is giving me problems.

Any help?

Sub GetImportFile()
Dim Filt As String
Dim FilterIndex As Integer
Dim FileName As Variant
Dim Title As String
Dim i As Integer
Dim Msg As String

' Set up list of file filters
Filt = "Comma Separated Files (*.csv),*.csv," & _
"All Files (*.*),*.*"

' Display *.* by default
FilterIndex = 2

' Set the dialog box caption
Title = "Select a File(s) to Import"

' Get the file name
FileName = Application.GetOpenFilename _
(FileFilter:=Filt, _
FilterIndex:=FilterIndex, _
Title:=Title, _
MultiSelect:=True)

' Exit if dialog box canceled
If Not IsArray(FileName) Then
MsgBox "No file was selected."
Exit Sub
End If

' Display full path and name of the files
For i = LBound(FileName) To UBound(FileName)
Msg = Msg & FileName(i) & vbCrLf
Next i
MsgBox "You selected:" & vbCrLf & Msg

>>> Workbooks.Open FileName:=(FileName) <<<

End Sub
 
You may try something like this:
For i = LBound(FileName) To UBound(FileName)
Workbooks.Open FileName:=FileName(i)
' your stuff for each CSV here
Next i

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top