I have a ton of .csv documents that are identical in their setup. They are all .csv and therefore all need simple formatting. My goal is quite simply to:
- Format them from .csv to regular columns (e.g., TextToColumns in Excel)
- Extract data from each separate file into one Excel sheet for further analysis
I have tried many things in VBA to loop through a folder with a macro, but I have not succeeded yet. In fact, none of the macros have done any changes whatsoever(?) I hope someone can help. One of my attempts is shown below.
Best, Karl
Dim filename As Variant
Dim a As Integer
a = 1
filename = Dir("/Users/karlemilthulstrup/Downloads/Test med kun 1Vp/Files*.csv")
Do While filename <> ""
Columns("A:A").Select
Selection.TextToColumns Destination:=Range("A1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
Semicolon:=False, Comma:=True, 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)), _
DecimalSeparator:=".", ThousandsSeparator:=",", TrailingMinusNumbers:= _
True
Loop
End Sub
Edit:
OPs Eureka! code from comments:
Sub test6()
Dim filename As Variant
Dim a As Integer
Dim MyFiles As String
a = 1
filename = Dir("/Users/karlemilthulstrup/Downloads/Test med kun 1Vp/Files.csv")
Do While filename <> ""
Workbooks.Open MyFiles
ActiveWorkbook.Close SaveChanges:=True
filename = Dir
Loop
End Sub