| ACCESS和EXECL结合的简单说明 |
|
| 作者:佚名 文章来源:ACCESSOFT 点击数: 本日:{$DayHits} 更新时间:2008-11-5 15:48:49 |
引用EXCEL Dim xlApp As Excel.Application Dim xlBook As Workbook, xlSheet As Worksheet Set xlApp = CreateObject("Excel.Application") Set xlApp = New Excel.Application Set xlBook = xlApp.Workbooks.Open(EXECL文件名) '打开要输出的EXECL文件 Set xlSheet = xlBook.Worksheets(1) '打开工作表,这里是第一个,可以设其他 xlApp.Visible = True '显示 xlSheet.CELLS(3, 3) = "'" & 要输出的内容 'CELLS(行,列) 单元格 xlSheet.PrintPreview '如果是要打印,只要把 PrintPreview 改为 PrintOut xlBook.Close SaveChanges:=False xlApp.Quit '退出
**************** For iCols = 0 to rs.Fields.Count - 1 ws.Cells(1, iCols + 1).Value = rs.Fields(iCols).Name Next ws.Range(ws.Cells(1, 1), _ ws.Cells(1, rs.Fields.Count)).Font.Bold = True ws.Range("A2").CopyFromRecordset rs
***************************** Private Sub CommandButton1_Click() Dim CNN As New ADODB.Connection Dim RST As New ADODB.Recordset Dim Stpath, strSQL As String Stpath = ThisWorkbook.Path & Application.PathSeparator & "学生档案.mdb" CNN.Open "provider=Microsoft.jet.OLEDB.4.0;data source=" & Stpath '& ";Jet OLEDB:Database Password=" & "123" If ComboBox3.Value = "" Then strSQL = "Select * from 档案 Where 籍贯 LIKE '" & ComboBox2.Value & "'" ElseIf ComboBox2.Value = "" Then strSQL = "Select * from 档案 Where 性别 LIKE '" & ComboBox3.Value & "'"
Else strSQL = "Select * from 档案 Where 性别 LIKE '" & ComboBox3.Value & "'" & "AND 籍贯 LIKE '" & ComboBox2.Value & "'" End If RST.Open strSQL, CNN Sheet1.Range("A2:G10000").ClearContents '删除原内容 Sheet1.Cells(2, 1).CopyFromRecordset RST RST.Close Set RST = Nothing '示放RST 的内存 Set CNN = Nothing '示放CNN的内存 End Sub
----------------------------------------- 江阴 钱玉炜 QQ:64898680 欢迎您访问我的专栏:http://www.accessoft.com/blog/?userid=16 如果您没有注册这个网上社区,请单击下面的链接进行注册,与我在社区进行交流:http://www.accessoft.com/reg/reg.asp?userid=16
作者简介:大学时学的计算机专业,对ACCESS了解不多,偶然的机会接触了ACCESS开发,于是潜心学习ACCESS,发现ACCESS开发是如此的易学、易用,开发速度快。欢迎大家与我交流,一起交流ACCESS的开发,享受access给我们带来的喜悦! |
| 文章录入:admin 责任编辑:admin |
|
上一篇文章: 每页打印一定行数后自动分页(报表分页)
下一篇文章: 没有了 |
| 【字体:小 大】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口】 |