I am trying to modify my macro for the import of XML files. I want the new macro to open CSV files. I attempted it but encountered a problem with the syntax for the Open Filename procedure.
Just below is the code with the problem. Further down is the whole script.
Please somebody assist in debugging this problem.
'Import files
For i = LBound(FileName) To UBound(FileName)
Sheets(i).Select
FileName2 = FileName(i)
ActiveWorkbook.Open FileName:=FileName2
Next i
Sub ImportMultipleFiles()
'Define variables
Dim Filt As String
Dim FilterIndex As Integer
Dim Title As String
Dim FileName As Variant
Dim FileName2 As Variant
Dim i As Integer
Dim j As Integer
Dim Msg As String
'Select files to Import
'Set up list of file filters
Filt = "CSV Files (*.csv) ,*.csv,"
'Display * * by default
FilterIndex = 5
'Set the dialog box caption
Title = "Select a File 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 Exit Sub
'Create sheets, one for each file to import
For j = LBound(FileName) To UBound(FileName) - 1
Sheets.Add After:=Sheets(j)
Sheets(j + 1).Select
Sheets(j + 1).Name = j + 1
Next j
'Import files
For i = LBound(FileName) To UBound(FileName)
Sheets(i).Select
FileName2 = FileName(i)
ActiveWorkbook.Open FileName:=FileName2
Cells.Select
Selection.RowHeight = 12.5
Selection.ColumnWidth = 15
Next i
End Sub
Bookmarks