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
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