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
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
Bạn xem lại cái file txt của bạn đúng đường dẫn chưa.
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).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!
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
code này sử dụng sao đây anh? anh có thể áp dụng vào file em được không?Public Function DesktopLocation() As String
DesktopLocation = CreateObject("WScript.Shell").SpecialFolders("Desktop")
End Function
phaiCuaToi = DestopAdrdress() & Application.PathSeparator & "xuat.txt"
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