DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel8, ""Table1", "D:\Exelfile.xls"
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel8, "Table2", "D:\Exelfile.xls"
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel8, "Querry1", "D:\Exelfile.xls"
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel8, "Querry2", "D:\Exelfile.xls"
'เป็นการส่งออก Table หรือ Querry ไปยังไฟล์ Exelfile.xls
strWkbkName = "D:\Exelfile.xls"
'กำหนดให้อ่านไฟล์
strWkSt = ""Table1"
Set objXL = CreateObject("Excel.Application")
objXL.Workbooks.Open (strWkbkName)
With objXL
.Worksheets(strWkSt) _
.Rows("1:1").Font.Bold = True
.Columns("A:Z").Autofit
'หรือ .Columns("B").Autofit ถ้าจะกำหนดเฉพาะคอลัมน์
.Rows("5:99").NumberFormat = "#,##0.00"
.Save
.Workbooks.Close
End With
strWkSt = "Table2"
Set objXL = CreateObject("Excel.Application")
objXL.Workbooks.Open (strWkbkName)
With objXL
.Worksheets(strWkSt) _
.Rows("1:1").Font.Bold = True
.Columns("A:Z").Autofit
.Save
.Workbooks.Close
End With
strWkSt = "Querry1"
Set objXL = CreateObject("Excel.Application")
objXL.Workbooks.Open (strWkbkName)
With objXL
.Worksheets(strWkSt) _
.Rows("1:1").Font.Bold = True
.Columns("A:Z").Autofit
.Save
.Workbooks.Close
End With
strWkSt = "Querry2"
Set objXL = CreateObject("Excel.Application")
objXL.Workbooks.Open (strWkbkName)
With objXL
.Worksheets(strWkSt) _
.Rows("1:1").Font.Bold = True
.Columns("A:Z").Autofit
.Rows("2:99").NumberFormat = "0.00"
.Save
.Workbooks.Close
End With
ไม่มีความคิดเห็น:
แสดงความคิดเห็น