Xuân Thanh > 07-07-12, 03:43 PM
For Each varFile In .SelectedItems
Me.txtTapTin = varFile
Next
Private Sub cmdImport_Click()
Call ImExAc(Me.txtTapTin, "tblKhachHang", "DanhSach")
End Sub
uronmapu > 07-07-12, 03:57 PM
Xuân Thanh > 07-07-12, 04:12 PM
uronmapu > 07-07-12, 04:45 PM
Xuân Thanh > 07-07-12, 04:56 PM
uronmapu > 07-07-12, 05:03 PM
uronmapu > 07-07-12, 10:03 PM
Function ImExAc(tblTabName As String, strFile As String, shSheet As String)
'tblTabName la ten table can Import du lieu
'strFile la ten duong dan den Workbook Ex co du lieu
'shSheet la ten Sheet cua Workbook strFile chua du lieu
'Sheet Ex co hang dau tien la hang tieu de(ten truong)
Dim Ex As New Excel.Application
Dim fileEx As Workbook
Set fileEx = Ex.Workbooks.Open(strFile)
Dim Ws As Worksheet
Set Ws = fileEx.Worksheets(shSheet)
Dim lfirstrow, lfirstcol, llastrow, llastcol As Long
With Ws.UsedRange
lfirstrow = .Row
lfirstcol = .Column
llastrow = .Rows(UBound(.Value)).Row
llastcol = .Columns(UBound(.Value, 2)).Column
End With
Dim Rs As Recordset
Set Rs = CurrentDb.OpenRecordset(tblTabName, dbOpenTable)
Dim i As Long
Dim j As Long
For i = lfirstrow + 1 To llastrow
Rs.AddNew
For j = lfirstcol To llastcol
Rs.Fields(j - lfirstcol) = Ws.Cells(i, j)
Next
Rs.Update
Next
fileEx.Close False
Set Ex = Nothing: Rs.Close
End Function
Xuân Thanh > 07-07-12, 10:19 PM
uronmapu > 07-07-12, 11:09 PM