Office中国论坛/Access中国论坛

标题: access操作excel数据并保存预览打印并退出 [打印本页]

作者: cqw    时间: 2006-7-5 23:43
标题: access操作excel数据并保存预览打印并退出
《《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
作者: wwwwa    时间: 2006-7-6 00:05
用RANGE的COPYFROMRECORDSET导数据速度要快些。
作者: fan0217    时间: 2006-7-6 00:49
这里有篇类似的帖子可以看看:http://www.office-cn.net/forum.php?mod=viewthread&tid=22539




欢迎光临 Office中国论坛/Access中国论坛 (http://www.office-cn.net/) Powered by Discuz! X3.3