I am trying to pull in a selected set of .csv files, then add each file to a workbook in its own worksheet to merge the data all into one excel workbook. I am having trouble naming the sheets the name of the file as each sheet is being pulled in. I have searched a lot and have various commented ways I have tried that did not work. Here is what I have so far:
Sub R_AnalysisMerger()
Dim WSA As Object
Dim bookList As Workbook
Dim SelectedFiles() As Variant
Dim NFile As Long
Dim FileName As String
Application.ScreenUpdating = False
'change folder path of excel files here
SelectedFiles = Application.GetOpenFilename(filefilter:="Excel Files (*.csv*), *.csv*", MultiSelect:=True)
For NFile = LBound(SelectedFiles) To UBound(SelectedFiles)
FileName = SelectedFiles(NFile)
Set bookList = Workbooks.Open(FileName)
Set WSA = ThisWorkbook.Worksheets.Add
'ActiveSheet.Name = Left(FileName, 31)
'ActiveWorksheet.Name.Add Name:= FileName
'ActiveWorkbook.Name Name:=FileName
'ThisWorkbook.Sheets.Name.Add (FileName)
'Change " A1" to the starting point for each file.
'Also change "A" column on "A10000" to the same column as start point
Range("A1:IV" & Range("A100000").End(xlUp).Row).Copy
ThisWorkbook.Worksheets(1).Activate
'Column
Range("A100000").End(xlUp).Offset(0, 0).PasteSpecial
Application.CutCopyMode = False
Cells.EntireColumn.AutoFit
bookList.Close
'ActiveWorkbook.Close
Next
Sheets("Sheet1").Select
Range("A1").Select
End Sub
WSA.Name = Left(FileName, 31)
– Parfait