Çözüldü TXT Kayıt Hatası

Katılım
10 Ağustos 2004
Mesajlar
292
Excel Vers. ve Dili
Excel 2021 - Türkçe
Merhaba aşağıdaki kod ile txt dosyası oluşturuyorum. Oluşan dosyanın txt “UTF-8” formatı olması gerekiyor ama kayıt sonrası baktığımda dosya formatı “Ürün Reçetesi ile UTF- 8“ formatında kayıt yapıyor. Konu hakkında bilgisi olan varsa yardımcı olabilir misiniz?


Sub Text()
Dim ws As Worksheet
Dim rng As Range
Dim i As Long
Dim txtLines As String
Dim filePath As String
Dim stream As Object

Set ws = ThisWorkbook.Sheets(1)

' B2:B501 aralığındaki hücreleri kontrol et
For i = 2 To 501
If Trim(ws.Cells(i, "B").Value) <> "" Then
txtLines = txtLines & ws.Cells(i, "V").Value & vbCrLf
End If
Next i

' Kaydedilecek dosya yolu
filePath = Application.ThisWorkbook.Path & "\Veriler.txt"

' UTF-8 ile dosyaya yazma
Set stream = CreateObject("ADODB.Stream")
With stream
.Charset = "utf-8"
.Open
.WriteText txtLines
.SaveToFile filePath, 2
.Close
End With

Set stream = Nothing
MsgBox "Dosya başarıyla oluşturuldu: " & filePath

End Sub
 
Katılım
11 Temmuz 2024
Mesajlar
363
Excel Vers. ve Dili
Excel 2021 Türkçe
Merhaba, yedek aldıktan sonra deneyebilir misiniz;

Kod:
Sub Text()
    Dim ws As Worksheet
    Dim i As Long
    Dim txtLines As String
    Dim filePath As String
    Dim stream As Object
    
    Set ws = ThisWorkbook.Sheets(1)
    
    For i = 2 To 501
        If Trim(ws.Cells(i, "B").Value) <> "" Then
            txtLines = txtLines & ws.Cells(i, "V").Value & vbCrLf
        End If
    Next i
    
    filePath = Application.ThisWorkbook.Path & "\Veriler.txt"
    
    Set stream = CreateObject("ADODB.Stream")
    With stream
        .Type = 2
        .Charset = "utf-8"
        .Open
        .WriteText txtLines
        .Position = 0
        
        Dim byteData() As Byte
        stream.Type = 1
        stream.Position = 3
        byteData = stream.Read
        .Close
        stream.Open
        stream.Write byteData
        stream.SaveToFile filePath, 2
        stream.Close
    End With
    Set stream = Nothing
    MsgBox "Dosya başarıyla oluşturuldu: " & filePath
End Sub
 
Katılım
10 Ağustos 2004
Mesajlar
292
Excel Vers. ve Dili
Excel 2021 - Türkçe
Kod çalıştı elinize sağlık teşekkür ederim.
 
Katılım
11 Temmuz 2024
Mesajlar
363
Excel Vers. ve Dili
Excel 2021 Türkçe
Rica ederim, iyi çalışmalar.
 
Üst