rx470与gtx970游戏评测:vb 导到EXCEL的码,请帮忙看看,对不对

来源:百度文库 编辑:神马品牌网 时间:2024/04/29 16:32:47
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
On Error Resume Next
Set xlBook = xlApp.Workbooks.Open("d:\text2.xls")
Set xlSheet = xlBook.Worksheets(1)
For j = 0 To mgrid.Columns.Count - 1
xlSheet.Cells(1, j + 1) = mgrid.Columns.Item(j).Caption
Next j
xlSheet.Cells(6, 1) = "i"
Adodc1.Recordset.MoveFirst
For i = 0 To Adodc1.Recordset.RecordCount - 1
mgrid.Row = i
For j = 0 To mgrid.Columns.Count - 1
mgrid.Col = j
'MsgBox DataGrid1.Text

If IsNull(mgrid.Text) = False Then
xlSheet.Cells(i + 2, j + 1) = mgrid.Text
End If
Next j
Next i
就是DATAGRID条数多时,导出无法终止,就是说,最后一条纪录,一直在导出。

既然已经使用 CreateObject("Excel.Application") ,那么定义时就不需要以这样的形式了
Dim xlApp As New Excel.Application
Dim xlBook As New Excel.Workbook
Dim xlSheet As New Excel.Worksheet
可以改为
Dim xlApp As Object
Dim xlBook As Object
Dim xlSheet As Object

其他应该没有语法错误