Skip to content

Instantly share code, notes, and snippets.

@DuongAQ
Last active February 27, 2018 04:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DuongAQ/7c449578ade94177048c6f8cb515ff6e to your computer and use it in GitHub Desktop.
Save DuongAQ/7c449578ade94177048c6f8cb515ff6e to your computer and use it in GitHub Desktop.
Sub Import_from_ClosedWB() 'Copy dữ liệu từ nhiều sheet trong 1 workbook đang đóng
Const sPath="D:\Temp\" 'Đường dẫn tới thư mục chứa workbook đang đóng
Dim sFil As String
Dim owb As Workbook
Dim ws As Worksheet
Dim sh As Worksheet
Application.ScreenUpdating = False 'Tắt chức năng cập nhật màn hình
Set ws=Sheet1
sFil=Dir(sPath & "*.xl*") 'Tên workbook cần lấy dữ liệu
Do While sFil <> "" 'Thực hiện khi workbook cần lấy dữ liệu có tồn tại
Set owb=Workbooks.Open(sPath & sFil)
For Each sh In ActiveWorkbook.Sheets 'Vòng lặp xét tới từng sheet
sh.[A2:AZ2000]=sh.[A2:AZ2000].Value 'Loại bỏ công thức, chỉ lấy giá trị
sh.Copy After:=ws 'Copy và paste sang workbook kết quả
owb.Close False 'Đóng workbook nhưng không thực hiện lưu
Next sh
sFil=Dir
Loop
Application.ScreenUpdating = True 'Mở chức năng cập nhật màn hình
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment