看看我为公司写的程序:
dim vbexcel As Excel.Application
dim xlbook As Excel.Workbook '定义Excel工作簿对象
dim xlsheet As Excel.Worksheet '定义Excel工作表对象
Dim row, col As Integer
Set vbexcel = New Excel.Application---这比使用createobject更好!!!
vbexcel.Caption = "拨号计费查询汇总报表"
vbexcel.Visible = True
'根据操作人员是否需要见到Excel此处可设为TRUE 或FALSE
Set xlbook = vbexcel.Workbooks.Open(App.Path & "\Month.xls")
Set xlsheet = xlbook.Worksheets("拨号计费查询汇总表")
'拨号计费查询汇总表为Excel模板工作表的名字
xlsheet.Activate
'下面是向单元格中填写数据:
row = xlsheet.Cells(1, 1).End(xlDown).row + 1
If DiaInputMonth.opt1 Then
xlsheet.Cells(row, 1).Value = DiaInputMonth.Combo1.Text & "年" & DiaInputMonth.Combo2.Text & "月"
Else
If DiaInputMonth.opt2 Then
xlsheet.Cells(row, 1).Value = DiaInputMonth.Combo3.Text & "年" & DiaInputMonth.Combo4.Text & "月~" & DiaInputMonth.Combo5.Text & "年" & DiaInputMonth.Combo6.Text
End If
End If
Do While Not DiaInputMonth.rsmonth.EOF
col = 2
xlsheet.Cells(row, col).Value = Str(DiaInputMonth.rsmonth("totalReadbytes").Value)
col = col + 1
xlsheet.Cells(row, col).Value = Str(DiaInputMonth.rsmonth("totalWriteBytes").Value)
col = col + 1
xlsheet.Cells(row, col).Value = Str(DiaInputMonth.rsmonth("totalTime").Value)
col = col + 1
xlsheet.Cells(row, col).Value = Str(Round((DiaInputMonth.rsmonth("totalTime").Value / 60), 1) * CDbl(GetSetting("西航拨号查询系统", "设置", "计费标准", 1)))
row = row + 1
DiaInputMonth.rsmonth.MoveNext
Loop