Hi all I come from VietNam and have a problem:
I have a workbook "MAIN.xlsm" with 3 sheets "DATA, Noibang, Ngoaibang", sheet "DATA" have 02 botton "Get_noibang and Get_ngoaibang"
When I press "Get_noibang" I want to get data from 03 workbook into the wb MAIN, sheet Noibang
3 wb have 02 sheet and the same sheet name (sheet1 "G000141" Range to get data B19:I785 and sheet2 "G000142" range data B19:G105
And When I press "Get_ngoaibang" I want to get data from 03 workbook into the wb MAIN, sheet ngoaibang,
03 wb have the same sheet name "G000142"; Range to get data B19:G105
The problem is when i press any Botton the data always get into sheet DATA, this mean Press "Get_noibang" data get into sheet DATA, not into sheet Noibang; Press "Get_ngoaibang" data get into sheet DATA, not into sheet ngoaibang
Plz Help me to correct the Code, This's MAIN.xlsm file: https://app.box.com/s/k7tzy35k9zp3rmtjk0o9savoibz45ytx
This is the Get_noibang
This is the Get_ngoaibang
Thanks in advanced
I have a workbook "MAIN.xlsm" with 3 sheets "DATA, Noibang, Ngoaibang", sheet "DATA" have 02 botton "Get_noibang and Get_ngoaibang"
When I press "Get_noibang" I want to get data from 03 workbook into the wb MAIN, sheet Noibang
3 wb have 02 sheet and the same sheet name (sheet1 "G000141" Range to get data B19:I785 and sheet2 "G000142" range data B19:G105
And When I press "Get_ngoaibang" I want to get data from 03 workbook into the wb MAIN, sheet ngoaibang,
03 wb have the same sheet name "G000142"; Range to get data B19:G105
The problem is when i press any Botton the data always get into sheet DATA, this mean Press "Get_noibang" data get into sheet DATA, not into sheet Noibang; Press "Get_ngoaibang" data get into sheet DATA, not into sheet ngoaibang
Plz Help me to correct the Code, This's MAIN.xlsm file: https://app.box.com/s/k7tzy35k9zp3rmtjk0o9savoibz45ytx
This is the Get_noibang
Code:
Option Explicit
Public Sub GPE_Noibang()
Dim FOb As Object, Fso As Object, Item, cn As Object, rs As Object, fOld As String, fNew As String
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Set Fso = CreateObject("Scripting.FileSystemObject")
Set cn = CreateObject("ADODB.Connection")
If Application.Version < 12 Then
fOld = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
fNew = ";Extended Properties=""Excel 8.0;HDR=No;IMEX=1"";"
Else
fOld = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source="
fNew = ";Extended Properties=""Excel 12.0;HDR=No;IMEX=1"";"
End If
With Application.FileDialog(msoFileDialogFilePicker)
.AllowMultiSelect = True
.Filters.Add "Microsoft Excel Files", "*.xls*", 1
If Not .Show = -1 Then
MsgBox "Ban chua chon File", vbInformation, "alonelove"
Exit Sub
End If
Range("A7").CurrentRegion.Offset(1).ClearContents
On Error Resume Next
For Each Item In .SelectedItems
If Left(Item, 1) <> "~" Then
cn.Open (fOld & Item & fNew)
Set rs = cn.Execute("select * from [G000141$B19:I785] where F1 Is Not Null")
If Not rs.EOF Then Range("A65000").End(3)(2).CopyFromRecordset rs
rs.Close
cn.Close
End If
Next Item
End With
Set cn = Nothing
Set rs = Nothing
MsgBox "Done!"
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
This is the Get_ngoaibang
Code:
Option Explicit
Public Sub GPE_NGOAI()
Dim FOb As Object, Fso As Object, Item, cn As Object, rs As Object, fOld As String, fNew As String
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Set Fso = CreateObject("Scripting.FileSystemObject")
Set cn = CreateObject("ADODB.Connection")
If Application.Version < 12 Then
fOld = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
fNew = ";Extended Properties=""Excel 8.0;HDR=No;IMEX=1"";"
Else
fOld = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source="
fNew = ";Extended Properties=""Excel 12.0;HDR=No;IMEX=1"";"
End If
With Application.FileDialog(msoFileDialogFilePicker)
.AllowMultiSelect = True
.Filters.Add "Microsoft Excel Files", "*.xls*", 1
If Not .Show = -1 Then
MsgBox "Ban chua chon File", vbInformation, "alonelove"
Exit Sub
End If
Range("A7").CurrentRegion.Offset(1).ClearContents
On Error Resume Next
For Each Item In .SelectedItems
If Left(Item, 1) <> "~" Then
cn.Open (fOld & Item & fNew)
Set rs = cn.Execute("select * from [G000142$B19:G105] where F1 Is Not Null")
If Not rs.EOF Then Range("A65000").End(3)(2).CopyFromRecordset rs
rs.Close
cn.Close
End If
Next Item
End With
Set cn = Nothing
Set rs = Nothing
MsgBox "Done!"
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
Thanks in advanced