急!将sql数据库内容导出至Excel表格,代码出错....
代码如下:提示用户定义类型未定义!什么原因?求教!!谢谢
Dim SQL As String
Dim i As Integer, r As Integer, c As Integer
Dim newxls As New Excel.Application '运行到该句出错:用户定义类型未定义!什么原因? Dim newbook As New Excel.Workbook
Dim newsheet As New Excel.Worksheet
Set newbook = newxls.Workbooks.Add '创建工作簿
Set newsheet = newbook.Worksheets(1) '创建工作表
If SQL <> "" Then
Form2.Adodc1.RecordSource = SQL
Form2.Adodc1.Refresh
End If
If Form2.Adodc1.Recordset.RecordCount > 0 Then
For i = 0 To Form2.DataGrid1.Columns.Count - 1
newsheet.Range("a1:l1").Interior.Color = RGB(153, 204, 0)
newsheet.Cells(1, i + 1) = Form2.DataGrid1.Columns(i).Caption
Next i
'指定表格内容
Form2.Adodc1.Recordset.MoveFirst
Do Until Form2.Adodc1.Recordset.EOF
r = Form2.Adodc1.Recordset.AbsolutePosition
For c = 0 To Form2.DataGrid1.Columns.Count - 1
Form2.DataGrid1.Col = c
newsheet.Range("a2:" & "l" & Form2.Adodc1.Recordset.RecordCount + 1).Interior.Color = RGB(255, 255, 153)
newsheet.Cells(r + 1, c + 1) = Form2.DataGrid1.Columns(c)
Next c
Form2.Adodc1.Recordset.MoveNext
Loop
newxls.Visible = True
End If