|
Private Sub lbl输出报表_Click()
Dim i As Integer, s As String
Dim EA As Excel.Application
Dim EB As Excel.Workbook, ES As Excel.Worksheet
Dim db As Database
Dim qdfTemp As QueryDef
On Error Resume Next
For i = 0 To lo.ListCount - 2
s = s & lo.Column(0, i) & ","
Next i
s = s & lo.Column(0, i)
If s <> "" Then
s = "select " & s & " from 报表1"
Else
s = "select * from 报表1"
End If
Set db = CurrentDb
With db
.QueryDefs.Delete "符合条件的报表"
Set qdfTemp = .CreateQueryDef("符合条件的报表", s)
DoCmd.OutputTo acOutputQuery, "符合条件的报表", acFormatXLS, CurDir & "\符合条件的报表.xls", False
.QueryDefs.Delete qdfTemp.Name
.Close
End With
Set EA = New Excel.Application
EA.Visible = True
Set EB = EA.Workbooks.Open(CurDir & "\符合条件的报表.xls")
Set ES = EB.Worksheets("符合条件的报表")
ES.Cells.Font.Name = 字体
ES.Cells.Font.Size = 字号
ES.Cells.Font.Bold = 加粗
ES.Cells.RowHeight = 字号 * 1.2
ES.Cells.Select
ES.Columns.AutoFit
ES.Cells(2, 1).Select
Set EA = Nothing
End Sub
只注意EA EB ES的语句,继续思考,自己先补充 控件,引用,有问题再提,我也要增强这个功能的,等 做完给你一份完整例子 |
|