Automating csv and txt files

dcng2691

New Member
Joined
Feb 28, 2021
Messages
2
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
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
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.

Forum statistics

Threads
1,213,549
Messages
6,114,264
Members
448,558
Latest member
aivin

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top