|
《《OA》access操作excel数据并保存预览打印并退出》
=================================
Dim xlApp As Excel.Application
Dim xlBook As Workbook, xlSheet As Worksheet
Set xlApp = CreateObject("Excel.Application")
Set xlApp = New Excel.Application
xlApp.Visible = True
Set xlBook = xlApp.Workbooks.Open("e:\data\database\temp.xls")
Set xlSheet = xlBook.Worksheets(1)
'打开数据表
Dim TableA As Recordset, DB As Database, Wks As Workspace
Dim tmpDate As String, tmpBuMen As String, tmpLeiBie As String, tmpJinE As Currency
Dim X As Long, Y As Long
Set Wks = Workspaces(0)
Set DB = CurrentDb()
Set TableA = DB.OpenRecordset("report-各材料本月领用表", dbOpenSnapshot) '打开查询
TableA.MoveFirst
tmpDate = TableA!数据启用日期
tmpBuMen = TableA!部门或单位名称
tmpLeiBie = TableA!类别
tmpJinE = TableA!支出金额
xlSheet.Cells(3, 1) = "制表日期:" + tmpDate + " 月"
Y = Val(tmpLeiBie)
X = Val(tmpBuMen) + 8
xlSheet.Cells(X, Y) = tmpJinE
Do Until TableA.EOF = True
tmpBuMen = TableA!部门或单位名称
tmpLeiBie = TableA!类别
tmpJinE = TableA!支出金额
Y = Val(tmpLeiBie)
X = Val(tmpBuMen) + 8
xlSheet.Cells(X, Y) = tmpJinE
TableA.MoveNext
Loop
TableA.close
xlBook.Save
xlSheet.PrintPreview
xlBook.close
xlApp.Quit |
|