kingwizard
Thành viên mới
- Tham gia
- 23/7/16
- Bài viết
- 36
- Được thích
- 1
Nhờ các bạn chỉnh sửa giúp macro ạ.
Sub Import_File()
Dim fd As FileDialog
Dim FileWasChosen As Boolean
Dim homeWorkbook As Workbook
Set homeWorkbook = ActiveWorkbook
Dim targetBook As Workbook
Dim targetSheet As Worksheet
Application.DisplayAlerts = False
Set fd = Application.FileDialog(msoFileDialogOpen)
fd.Filters.Add "Any Excel Files", "*.csv*"
FileWasChosen = fd.Show
If Not FileWasChosen Then
MsgBox "You didn't select a file"
Exit Sub
End If
fd.Execute
Set targetBook = ActiveWorkbook
Set targetSheet = targetBook.Worksheets(1)
targetSheet.Copy After:=homeWorkbook.Sheets(homeWorkbook.Sheets.Count)
targetBook.Close
Application.DisplayAlerts = True
With homeWorkbook.Sheets(homeWorkbook.Sheets.Count)
End With
End Sub
Hiện tại macro trên mặc dù cho chọn nhiều file nhưng chỉ add được 1 file vào file excel chính.
Mình muốn chọn bao nhiêu file thì add bấy nhiêu file ạ.
Xin cảm ơn
Sub Import_File()
Dim fd As FileDialog
Dim FileWasChosen As Boolean
Dim homeWorkbook As Workbook
Set homeWorkbook = ActiveWorkbook
Dim targetBook As Workbook
Dim targetSheet As Worksheet
Application.DisplayAlerts = False
Set fd = Application.FileDialog(msoFileDialogOpen)
fd.Filters.Add "Any Excel Files", "*.csv*"
FileWasChosen = fd.Show
If Not FileWasChosen Then
MsgBox "You didn't select a file"
Exit Sub
End If
fd.Execute
Set targetBook = ActiveWorkbook
Set targetSheet = targetBook.Worksheets(1)
targetSheet.Copy After:=homeWorkbook.Sheets(homeWorkbook.Sheets.Count)
targetBook.Close
Application.DisplayAlerts = True
With homeWorkbook.Sheets(homeWorkbook.Sheets.Count)
End With
End Sub
Hiện tại macro trên mặc dù cho chọn nhiều file nhưng chỉ add được 1 file vào file excel chính.
Mình muốn chọn bao nhiêu file thì add bấy nhiêu file ạ.
Xin cảm ơn