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) '创建工作表
Dim SQL As String
Dim i, c, r As Long
Adolist.Refresh
If Adolist.Recordset.RecordCount > 0 Then
For i = 0 To DataGrid1.Columns.Count - 1
newsheet.Cells(1, i + 1) = DataGrid1.Columns(i).Caption
Next i
'指定表格内容
Adolist.Recordset.MoveFirst
For i = 1 To Adolist.Recordset.RecordCount
r = Adolist.Recordset.AbsolutePosition
For c = 0 To DataGrid1.Columns.Count - 1
DataGrid1.Col = c
newsheet.Cells(r + 1, c + 1) = DataGrid1.Columns(c)
Next c
Adolist.Recordset.MoveNext
Next i
Adolist.Refresh
Dim myval As Long
Dim mystr As String
myval = MsgBox("是否保存该Excel表?", vbYesNo, "提示窗口")
If myval = vbYes Then
mystr = InputBox("请输入文件名称", "输入窗口")
If Len(mystr) = 0 Then
MsgBox "系统不允许文件名称为空!", , "提示窗口"
Exit Sub
End If
On Error GoTo ErrSave
newsheet.SaveAs App.Path & "\Excel文件\" & mystr & "(财务查询).xls"
MsgBox "Excel文件保存成功,位置:" & App.Path & "\Excel文件\" & mystr & "(财务查询).xls", , "提示窗口"
newxls.Quit
ErrSave:
Exit Sub
MsgBox Err.Description, , "提示窗口"
End If
End If
Case 4
Unload Me
End Select