DoquangLam > 12-03-14, 10:01 AM
DoquangLam > 12-03-14, 11:29 AM
MTNQ > 21-03-14, 02:06 AM
Private Sub Command3_Click()
On Error GoTo Err_Command3_Click
Dim xlApp As Excel.Application
Dim wb As Workbook
Dim strPath As String
Dim i As Byte
strPath = "C:\Vidu.xls"
'DoCmd.RunMacro "Macro1"
DoCmd.OutputTo acOutputReport, "R_BKHDBan_Excel", "MicrosoftExcelBiff8(*.xls)", strPath, False, "", , acExportQualityPrint
Set xlApp = New Excel.Application
Set wb = xlApp.Workbooks.Open(strPath)
wb.Worksheets(1).Range("1:1").EntireRow.Delete 'Xóa dòng tiêu đề
For i = 1 To 16
wb.Worksheets(1).Rows("1:1").Insert Shift:=xlDown 'Chèn thêm vào 16 dòng
Next i
xlApp.Visible = True 'Hiện file excel lên
Set wb = Nothing
Set xlApp = Nothing
Exit_Command3_Click:
Exit Sub
Err_Command3_Click:
If Not xlApp Is Nothing Then
xlApp.Quit
Set xlApp = Nothing
End If
MsgBox Err.Description
Resume Exit_Command3_Click
End Sub
Private Sub Command4_Click()
On Error GoTo Err_Command4_Click
Dim rs As DAO.Recordset
Dim XL As Excel.Application
Dim wb As Workbook
Set rs = CurrentDb.OpenRecordset("QryBKHDBan_Excel", dbOpenSnapshot)
Set XL = CreateObject("Excel.Application")
Set wb = XL.Workbooks.Open("C:\Vidu.xls")
With wb
.Worksheets(1).Range("A17").CopyFromRecordset rs
.Worksheets(1).Columns.EntireColumn.AutoFit
.Save
.Close False
End With
Set rs = Nothing
Set wb = Nothing
XL.Quit
Set XL = Nothing
Exit_Command4_Click:
Exit Sub
Err_Command4_Click:
Set rs = Nothing
If Not XL Is Nothing Then
XL.Quit
Set XL = Nothing
End If
MsgBox Err.Description
Resume Exit_Command4_Click
End Sub
DoquangLam > 21-03-14, 08:55 AM
MTNQ > 21-03-14, 10:41 AM
DoquangLam > 21-03-14, 11:22 AM
MTNQ > 21-03-14, 01:25 PM
DoquangLam > 21-03-14, 03:08 PM
MTNQ > 22-03-14, 01:48 AM
DoquangLam > 23-03-14, 07:32 AM