1
Good afternoon. I have the macro below and it already does almost what I want (creates a txt file with the data of the Historico spreadsheet, always rewriting the file, ie, does not create several copies), but this Historico spreadsheet, contains names of football teams and when finding strange names like: "Śląsk Wrocław , Górnik Łęczna , Wisła Płock" the macro hangs and appears the message: Runtime error '5': Invalid argument or procedure call
Option Explicit
Sub Creartxt()
'tem que ativar a referência => Microsoft Scripting Runtime
Dim NombreArchivo, RutaArchivo As String
Dim obj As FileSystemObject
Dim tx As Scripting.TextStream
Dim Ht As Worksheet
Dim i, j, nFilas, nColumnas As Integer
NombreArchivo = "Batch"
RutaArchivo = ActiveWorkbook.Path & "\" & NombreArchivo & ".txt"
Set Ht = Worksheets("Historico")
Set obj = New FileSystemObject
Set tx = obj.CreateTextFile(RutaArchivo)
nColumnas = Ht.Range("A1", Ht.Range("A1").End(xlToRight)).Cells.Count
nFilas = Ht.Range("A2", Ht.Range("A2").End(xlDown)).Cells.Count
For i = 1 To nFilas
    If Ht.Cells(i + 1, 4).Value <> "" Then
    For j = 1 To nColumnas
        tx.write Ht.Cells(i + 1, j).Value  'É nesta parte onde a macro trava
        If j < nColumnas Then tx.write "|"
    Next j
    tx.writeLine
    End If
Next i
End Sub
Behold this site
– danieltakeshi
And this answer has a part of saving txt file with UTF-8 encoding, with this encoding these errors will disappear.
– danieltakeshi