xuất file txt qua excel (1 người xem)

Liên hệ QC

Người dùng đang xem chủ đề này

huonglien1901

GPE là ngôi nhà thứ 2 của tôi!!!
Tham gia
17/4/16
Bài viết
2,701
Được thích
2,434
Giới tính
Nam
Nghề nghiệp
Nhân viên kỹ thuật in ấn
Chào mọi người!

Em muốn xuất file txt qua excel thì phải làm như thế nào nhờ mọi người giúp

Em cảm ơn mọi người nhiều
 

File đính kèm

Đâu cần phải xuất bạn vì trong file txt của bản chẳng có cái gì cả.
 
Upvote 0
Dạ, tại em gửi nhầm file, em gủi lại cho anh xem
 

File đính kèm

Upvote 0
Dùng thử đoạn code này thử xem.
Mã:
Public Sub GPE()
Dim myFile As String, textline As String, i As Long
   myFile = "C:\Xuat.txt"
   i = 1
    Open myFile For Input As #1
        Do Until EOF(1)
            i = i + 1
            Line Input #1, textline
            Cells(i, 1) = textline
        Loop
    Close #1
End Sub
 
Upvote 0
Dùng thử đoạn code này thử xem.
Mã:
Public Sub GPE()
Dim myFile As String, textline As String, i As Long
   myFile = "C:\Xuat.txt"
   i = 1
    Open myFile For Input As #1
        Do Until EOF(1)
            i = i + 1
            Line Input #1, textline
            Cells(i, 1) = textline
        Loop
    Close #1
End Sub

code bị lỗi rồi anh ơi. nó bị lỗi dòng này

Open myFile For Input As #1(lỗi 53)
 
Upvote 0
Anh ơi, ví dụ em thêm nhiều file txt thì con trỏ thêm bắt dầu kế tiếp.

Anh hỗ trợ giúp em với!
 
Upvote 0
Anh ơi, ví dụ em thêm nhiều file txt thì con trỏ thêm bắt dầu kế tiếp.

Anh hỗ trợ giúp em với!
Bạn sửa lại thế này, nhớ đặt file txt nằm chung với thư mục chứa file excel, còn đường dẫn đến màn hình desktop của bạn làm sao tôi biết đường dẫn như thế nào (Mỗi máy mỗi khác).
Mã:
Public Sub GPE()
Dim myFile As String, textline As String, i As Long
   myFile = ThisWorkbook.Path & "\Xuat.txt"
   i = Sheet1.Range("A65000").End(xlUp).Row
    Open myFile For Input As #1
        Do Until EOF(1)
            i = i + 1
            Line Input #1, textline
            Cells(i, 1) = textline
        Loop
    Close #1
End Sub
 
Upvote 0
Public Function DesktopLocation() As String
DesktopLocation = CreateObject("WScript.Shell").SpecialFolders("Desktop")
End Function

phaiCuaToi = DestopAdrdress() & Application.PathSeparator & "xuat.txt"
 
Upvote 0
Public Function DesktopLocation() As String
DesktopLocation = CreateObject("WScript.Shell").SpecialFolders("Desktop")
End Function

phaiCuaToi = DestopAdrdress() & Application.PathSeparator & "xuat.txt"
code này sử dụng sao đây anh? anh có thể áp dụng vào file em được không?
 
Upvote 0
Bạn sửa lại thế này, nhớ đặt file txt nằm chung với thư mục chứa file excel, còn đường dẫn đến màn hình desktop của bạn làm sao tôi biết đường dẫn như thế nào (Mỗi máy mỗi khác).
Mã:
Public Sub GPE()
Dim myFile As String, textline As String, i As Long
   myFile = ThisWorkbook.Path & "\Xuat.txt"
   i = Sheet1.Range("A65000").End(xlUp).Row
    Open myFile For Input As #1
        Do Until EOF(1)
            i = i + 1
            Line Input #1, textline
            Cells(i, 1) = textline
        Loop
    Close #1
End Sub

Dạ code ra đúng rồi anh ơi!

Em cảm ơn anh rất nhiều!
 
Upvote 0
Web KT

Bài viết mới nhất

Back
Top Bottom