Hello
I was looking a code like this on internet, but i have to do some modifications.
Every month y have different folders that contains csv and txt files.
The txt files have to be separated with the text to columns option and the csv files data comes separated with '|'.
This is what i diid with the code but I get an error saying that i cannot save the file with the same name as the original one.
Dim MyFolder As String
Dim myfile As String
Dim folderName As String
With Application.FileDialog(msoFileDialogFolderPicker)
.AllowMultiSelect = False
If .Show = -1 Then
folderName = .SelectedItems
End If
End With
myfile = Dir(folderName & "\*.fac.txt")
Do While myfile <> ""
Workbooks.OpenText Filename:=folderName & "\" & myfile, Origin:=437, StartRow:=1, DataType:=xlFixedWidth, FieldInfo:=Array(Array(0, 1), _
Array(4, 1), Array(6, 1), Array(12, 1), Array(15, 1), Array(21, 1), Array(24, 1)), TrailingMinusNumbers:=True
Call FormatoArchivosTxt
'save as excel file
ActiveWorkbook.SaveAs Filename:=folderName & "\" & Replace(myfile, ".txt", ".xlsx")
'use below 3 lines if you want to close the workbook right after saving, so you dont have a lots of workbooks opened
' ActiveWorkbook.Close
' myfile = Dir
Loop
I was looking a code like this on internet, but i have to do some modifications.
Every month y have different folders that contains csv and txt files.
The txt files have to be separated with the text to columns option and the csv files data comes separated with '|'.
This is what i diid with the code but I get an error saying that i cannot save the file with the same name as the original one.
Dim MyFolder As String
Dim myfile As String
Dim folderName As String
With Application.FileDialog(msoFileDialogFolderPicker)
.AllowMultiSelect = False
If .Show = -1 Then
folderName = .SelectedItems
End If
End With
myfile = Dir(folderName & "\*.fac.txt")
Do While myfile <> ""
Workbooks.OpenText Filename:=folderName & "\" & myfile, Origin:=437, StartRow:=1, DataType:=xlFixedWidth, FieldInfo:=Array(Array(0, 1), _
Array(4, 1), Array(6, 1), Array(12, 1), Array(15, 1), Array(21, 1), Array(24, 1)), TrailingMinusNumbers:=True
Call FormatoArchivosTxt
'save as excel file
ActiveWorkbook.SaveAs Filename:=folderName & "\" & Replace(myfile, ".txt", ".xlsx")
'use below 3 lines if you want to close the workbook right after saving, so you dont have a lots of workbooks opened
' ActiveWorkbook.Close
' myfile = Dir
Loop