Hi, I have poorly designed a VBA macro that opens/exports .csv data to an excel... works fine but when I export - say 10 csv, I'm left with 10 csv opened... I am trying to extend the coding so that the VBA macro also closes the csv files - thank you
Sub Macro1()
'
' Macro1 Macro
'
'
Set CSVPath = Sheets("Control").Range("CSV_Path")
Set CSVFile = Sheets("Control").Range("CSV_File")
Workbooks.Open Filename:=(CSVPath & CSVFile)
Rows("1:1").Select
Selection.Delete Shift:=xlUp
Range("A1").Select
Selection.End(xlDown).Select
xMoon = ActiveCell.Row + 1
Range(Cells(1, 1), Cells(xMoon, 1)).Select
Selection.TextToColumns Destination:=Range("A1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
Semicolon:=True, Comma:=False, Space:=False, Other:=False, FieldInfo _
:=Array(Array(1, 1), Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1), _
Array(7, 1), Array(8, 1), Array(9, 1), Array(10, 1), Array(11, 1), Array(12, 1), Array(13, 1 _
), Array(14, 1), Array(15, 1), Array(16, 1), Array(17, 1), Array(18, 1), Array(19, 1), Array _
(20, 1), Array(21, 1), Array(22, 1), Array(23, 1), Array(24, 1), Array(25, 1), Array(26, 1), _
Array(27, 1), Array(28, 1), Array(29, 1), Array(30, 1), Array(31, 1), Array(32, 1), Array( _
33, 1)), TrailingMinusNumbers:=True
Range(Cells(1, 1), Cells(xMoon, 33)).Select
Selection.Copy
Windows("TB_BB_Monitoring_2020.xlsm").Activate
Sheets("CSV").Select
Range("A1").Select
Selection.End(xlDown).Select
xStar = ActiveCell.Row + 1
Cells(xStar, 1).Select
ActiveSheet.Paste
Sub Macro1()
'
' Macro1 Macro
'
'
Set CSVPath = Sheets("Control").Range("CSV_Path")
Set CSVFile = Sheets("Control").Range("CSV_File")
Workbooks.Open Filename:=(CSVPath & CSVFile)
Rows("1:1").Select
Selection.Delete Shift:=xlUp
Range("A1").Select
Selection.End(xlDown).Select
xMoon = ActiveCell.Row + 1
Range(Cells(1, 1), Cells(xMoon, 1)).Select
Selection.TextToColumns Destination:=Range("A1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
Semicolon:=True, Comma:=False, Space:=False, Other:=False, FieldInfo _
:=Array(Array(1, 1), Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1), _
Array(7, 1), Array(8, 1), Array(9, 1), Array(10, 1), Array(11, 1), Array(12, 1), Array(13, 1 _
), Array(14, 1), Array(15, 1), Array(16, 1), Array(17, 1), Array(18, 1), Array(19, 1), Array _
(20, 1), Array(21, 1), Array(22, 1), Array(23, 1), Array(24, 1), Array(25, 1), Array(26, 1), _
Array(27, 1), Array(28, 1), Array(29, 1), Array(30, 1), Array(31, 1), Array(32, 1), Array( _
33, 1)), TrailingMinusNumbers:=True
Range(Cells(1, 1), Cells(xMoon, 33)).Select
Selection.Copy
Windows("TB_BB_Monitoring_2020.xlsm").Activate
Sheets("CSV").Select
Range("A1").Select
Selection.End(xlDown).Select
xStar = ActiveCell.Row + 1
Cells(xStar, 1).Select
ActiveSheet.Paste