Giúp Macro Import dữ liệu từ file text! (1 người xem)

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

xuantam1991

Thành viên mới
Tham gia
4/7/14
Bài viết
25
Được thích
0
Mình muốn làm một Macro Import dữ liệu từ file text vào excel..
Khi ấn import sẽ hiện lên hộp thoại duyệt đến file text.
và dữ liệu Import vào sẽ bắt đầu ở ô A1 định dạng text.
Mình dùng Macro record nhưng k thay đổi được đường dẫn..
anh em chỉ giúp.. cám ơn nhiều.
 

File đính kèm

Mình muốn làm một Macro Import dữ liệu từ file text vào excel..
Khi ấn import sẽ hiện lên hộp thoại duyệt đến file text.
và dữ liệu Import vào sẽ bắt đầu ở ô A1 định dạng text.
Mình dùng Macro record nhưng k thay đổi được đường dẫn..
anh em chỉ giúp.. cám ơn nhiều.

Mình hộ trỡ bạn code thay đổi đường dẫn còn trong nội bộ bạn tự viết

[GPECODE=vb]
Sub LoadFile()
Dim ListF
With Application
.ScreenUpdating = False
ListF = Application.GetOpenFilename("Text Files (*.txt), *.txt" _
, , "Select *.txt Files", , True)
If IsArray(ListF) Then
'Code xử lý của bạn
End If
.ScreenUpdating = True
End With
End Sub


[/GPECODE]
 
Upvote 0
Bạn giúp mình nốt phần code import với.. mình sửa thêm đoạn code record vào nhưng không được.. chỉ cần dữ liệu dạng text và bắt đầu ô A1 thui.. mình mới dùng nên gà mấy cái này lắm.. thank bạn nhiều!!

Mã:
Sub LoadFile()    Dim ListF
With Application
.ScreenUpdating = False
    ListF = Application.GetOpenFilename("Text Files (*.txt), *.txt" _
          , , "Select *.txt Files", , True)
    With ActiveSheet.QueryTables.Add(Connection:=ListF, Destination:=Range( _
        "$A$1"))
        .CommandType = 0
        .Name = "ListF"
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .TextFilePromptOnRefresh = False
        .TextFilePlatform = 437
        .TextFileStartRow = 1
        .TextFileParseType = xlFixedWidth
        .TextFileTextQualifier = xlTextQualifierDoubleQuote
        .TextFileConsecutiveDelimiter = False
        .TextFileTabDelimiter = True
        .TextFileSemicolonDelimiter = False
        .TextFileCommaDelimiter = False
        .TextFileSpaceDelimiter = False
        .TextFileColumnDataTypes = Array(2, 1, 1, 1)
        .TextFileFixedColumnWidths = Array(35, 5, 3)
        .TextFileTrailingMinusNumbers = True
        .Refresh BackgroundQuery:=False
    End With




.ScreenUpdating = True
End With
End Sub
 
Lần chỉnh sửa cuối:
Upvote 0

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

Back
Top Bottom