excel报表输出问题
大家好!请教一个问题,我如下编码运行中总出线mgrid为定义变量,修改了几次也不行。请大家帮忙指点、修改一下谢谢!!!Private Sub Command8_Click()
Dim i As Integer
Dim j As Integer
Dim xlApp As New Excel.Application
Dim xlBook As New Excel.Workbook
Dim xlSheet As New Excel.Worksheet
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True
Set xlBook = xlApp.Workbooks.Add
Set xlSheet = xlBook.Worksheets(1)
Set mgrid = grdLoupan
For j = 0 To mgrid.Columns.Count - 1
xlSheet.Cells(1, j + 1) = mgrid.Columns.Item(j).Caption
Next j
rs_xingneng.Recordset.MoveFirst
i = 0
Do While Not rs_xingneng.Recordset.EOF
For j = 0 To mgrid.Columns.Count - 1
xlSheet.Cells(i + 2, j + 1) = rs_xingneng.Recordset.Fields(j).Value
Next j
rs_xingneng.Recordset.MoveNext
i = i + 1
End Sub