Sub tonghop()
Application.ScreenUpdating = False
Range("A6:G" & Range("A65000").End(3).Row + 1).ClearContents
Set cn = CreateObject("ADODB.Connection")
cn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & ThisWorkbook.Path & "\danhsach.xls;Extended Properties=""Excel 12.0 Xml;HDR=NO;IMEX=1"";"
Range("B6").CopyFromRecordset cn.Execute("SELECT f5,f7,f8,f15,f22,f30 FROM [doc1$A15:AK60000] where f2 >0")
Range("A6:A" & Range("B65000").End(3).Row).Value = "=row()-5"
Range("A6:G" & Range("B65000").End(3).Row).Borders.LineStyle = xlContinuous
ActiveWorkbook.Worksheets("DOI B07").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("DOI B07").Sort.SortFields.Add Key:=Range("C6:C60000"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
End Sub
Khi mình mở file danhsach.xls thì mới chạy được macro trên, có cách nào không cần mở file danhsach.xls mà vẫn chạy code trên được không?
Nhờ các anh chị giúp đỡ. Xin cám ơn !!
Application.ScreenUpdating = False
Range("A6:G" & Range("A65000").End(3).Row + 1).ClearContents
Set cn = CreateObject("ADODB.Connection")
cn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & ThisWorkbook.Path & "\danhsach.xls;Extended Properties=""Excel 12.0 Xml;HDR=NO;IMEX=1"";"
Range("B6").CopyFromRecordset cn.Execute("SELECT f5,f7,f8,f15,f22,f30 FROM [doc1$A15:AK60000] where f2 >0")
Range("A6:A" & Range("B65000").End(3).Row).Value = "=row()-5"
Range("A6:G" & Range("B65000").End(3).Row).Borders.LineStyle = xlContinuous
ActiveWorkbook.Worksheets("DOI B07").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("DOI B07").Sort.SortFields.Add Key:=Range("C6:C60000"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
End Sub
Khi mình mở file danhsach.xls thì mới chạy được macro trên, có cách nào không cần mở file danhsach.xls mà vẫn chạy code trên được không?
Nhờ các anh chị giúp đỡ. Xin cám ơn !!

