(This is a revision of a similar question)
I often import a folder of .csv files into the active workbook (the workbook with the macro), so I want to automate this with VBA.
I pieced together the following script, but it inserts blank worksheet after every imported .csv files.
Sub ImportCSV() With Application.FileDialog(msoFileDialogFolderPicker) .Title = "Select folder of .csv files." .Show strDir = .SelectedItems.Item(1) End With strFile = Dir(strDir & "\" & "*.csv") Set wbSink = ThisWorkbook Do While strFile <> "" Set wbSource = Workbooks.Open(strDir & "\" & strFile) wbSource.Sheets.Copy wbSink.Sheets.Add wbSource.Close False strFile = Dir() Loop End Sub
That is, after the first imported sheet it adds "Sheet2", then after the next imported sheet it adds "Sheet3", and so on. What is the fix?