ACCESS和EXECL结合的简单说明
时间:2008-11-05 15:48 来源:网络 作者:佚名 阅读:次
引用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
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
(责任编辑:admin)
顶一下
(0)
0%
踩一下
(0)
0%
相关内容
- ·解决Access在页面设置中设置边距无法保
- ·Access通用报表打印设置
- ·在Access中使用自动化打印报告
- ·报表奇偶分页打印
- ·access输出资料到word用于打印
- ·支票打印的日期大写问题Access2007
- ·[报表]报表跨节垂直居中例子
- ·ACCESS-VBA编程 第八章 报表
- ·用Access2007解决支票打印的日期大写问
- ·自由设置页码打印报表
- ·ACCESS和EXECL结合的简单说明
- ·每页打印一定行数后自动分页(报表分页
- ·在VB中用代码打印ACCESS报表
- ·[原创]在 Access 2000中变通实现弹出式
- ·在Access 2002中打印报表的关系图
- ·Access轻松实现多数据批量打印
最新内容
推荐内容