Good afternoon. I have the macro below and it already does almost what I want (it creates a txt file with the data of the Historico worksheet, always rewriting the file, that is, it does not create several copies), however this History sheet contains soccer team names and when finding strange names such as "Śląsk Wrocław, Górnik Łęczna, Wisła Płock" the macro hangs and the message appears: Run-time error '5': Argument or invalid procedure call
Option Explicit
Sub CreateTXT ()
'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