Không chạy được macro "Copy nhiều sheet vào 1 file Excel"

Liên hệ QC

alonelove

Thành viên chính thức
Tham gia
7/9/10
Bài viết
52
Được thích
2
Em dùng macro trên GPE để copy nhiều sheet từ nhiều file khác nhau sang 1 File Excel mà nó báo lỗi như hình dưới:
Macro chạy nó ra hình này:

b50ee98a7a1b8a2949206253be59d860_52616263.1.jpg


Nhấn Debug xem thấy lỗi này:


c849c9f791aca4d267fde80b2f75c5df_52616265.2.jpg


Em cần copy khoảng 120 sheet ở 120 file khác nhau sang chung 1 file (quá nhiều để làm thủ công.hichic. Đoạn mã đây ạ (chỉ lấy tên 2 sheet đầu tiên thôi):
Mã:
Private Sub CommandButton1_Click()
    Application.ScreenUpdating = 0
    Dim FileNguon, i
    Dim FileName(), ShName()
      FileName = Array("sacombank01.xls", "msb01.xls")
       ShName = Array("sacombank01.xls", "msb01.xls")
        For i = 0 To UBound(FileName)
         FileNguon = ThisWorkbook.Path & "\" & FileName(i)
         ThisWorkbook.Worksheets(ShName(i)).Select
           With ActiveSheet
            .Cells.Clear
             .[a1].Select
           With .QueryTables.Add(Connection:=Array("OLEDB;Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" _
          & FileNguon & ";Jet OLEDB:Engine Type=35"), Destination:=Selection)
         .CommandType = 3
        .CommandText = Array("sheet1$")
       .Refresh BackgroundQuery:=False
       End With
      .UsedRange.Columns.AutoFit
    End With
    Next
End Sub


Kính mong Quý thầy và các bạn trên GPE giúp đỡ |||||
 
Web KT
Back
Top Bottom