Skip to main content

AccessTr.neT


Txt Dosyasından Bilgi Alma

Txt Dosyasından Bilgi Alma

#7
Hocam merhaba,

001,00001,1 2022/06/21 09:59:43 000
cihazno, sicilno, gc, gtarih, gsaat, nedeni

Saygılarımla,
Ahmet Yenginoğlu
Cevapla
#8
eklediğiniz dosyada nedeni alanı yada ona benzer metin alanı olmadığı için sadece nedeni alanı dışındakileri ekledim
Sub OpenTextFileTest()
    Dim result As Integer
    On Error GoTo Err

    yol = getFileName
   
        Response = MsgBox("Dosya bulundu verileri yüklemek ister misiniz?", vbYesNo, "UYARI")
        If Response = 7 Then Exit Sub
                
        Dim strTextLine As String
        Dim iFile As Integer: iFile = FreeFile
        Open yol For Input As #iFile
        Do Until EOF(1)
            Line Input #1, strTextLine
            tmpdz = Split(strTextLine)
            sonuc = tmpdz(0) & ",#" & tmpdz(1) & "#,#" & tmpdz(2) & "#"   'cihazno,sicilno,gc,gtarih,gsaati,ctarihi,csaati
            CurrentDb.Execute ("insert into tblAlınanVeriler (cihazno,sicilno,gc,gtarih,gsaati) values (" & sonuc & ") ")
        Loop
        Close #iFile
 msgbox "bitti"
Err:
If Err.Number = 62 Then
    MsgBox "Belirttiğiniz dosya boş", vbOKOnly, "UYARI"
Else
    End If
Exit Sub

Çıkış:
End Sub
Cevapla
#9
Hocam çok teşekkür ederim. Sağolun,

Saygılarımla,
Ahmet Yenginoğlu
Cevapla
#10
rica ederim
iyi çalışmalar
Cevapla
#11
Berduş Hocam merhaba,

aynı txt dosyasından Excel e nasıl verileri alabilirim.

Saygılarımla,
Ahmet Yenginoğlu
Cevapla
#12
Kod:
Sub OpenTextFileTest()
    On Error GoTo ErrHandler

    Dim yol As String
    Dim Response As Variant
    Dim strTextLine As String
    Dim tmpdz As Variant
    Dim sonuc As String
    Dim iFile As Integer
    
    yol = getFileName
    
    Response = MsgBox("Dosya bulundu verileri yüklemek ister misiniz?", vbYesNo, "UYARI")
    If Response = vbNo Then Exit Sub
    
    iFile = FreeFile
    Open yol For Input As #iFile
    
    Do Until EOF(iFile)
        Line Input #iFile, strTextLine
        tmpdz = Split(strTextLine)
        sonuc = tmpdz(0) & ",#" & tmpdz(1) & "#,#" & tmpdz(2) & "#"
        ThisWorkbook.Sheets("Sheet1").Range("A1").CurrentRegion.ListObject.ListRows.Add AlwaysInsert:=True
        ThisWorkbook.Sheets("Sheet1").Range("A1:C1").Value = Split(sonuc, ",")
    Loop
    
    Close #iFile
    MsgBox "bitti"
    
ErrHandler:
    If Err.Number = 62 Then
        MsgBox "Belirttiğiniz dosya boş", vbOKOnly, "UYARI"
    End If
End Sub

şeklinde excele uyarlayabilirsiniz.
Cevapla

Bir hesap oluşturun veya yorum yapmak için giriş yapın

Yorum yapmak için üye olmanız gerekiyor

ya da
Task