Dim conn As ADODB.Connection
Dim myrec As ADODB.Recordset
Dim adopre As ADODB.Parameter
Dim cmd As ADODB.Command
Set conn = New ADODB.Connection
Set myrec = New ADODB.Recordset
Set adopre = New ADODB.Parameter
Set cmd = New ADODB.Command
conn.ConnectionString = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=DB_PurchaseOrder;Data Source=."
conn.Open
cmd.ActiveConnection = conn
cmd.CommandType = adCmdStoredProc
cmd.CommandText = "sp_recordset"
Set adopre = cmd.CreateParameter("@bbb", adInteger, adParamInput)
cmd.Parameters.Append adopre
cmd.Parameters("@bbb").Value = "5"
Set myrec = cmd.Execute()
Dim myexcel As New Excel.Application
Dim mybook As New Excel.Workbook
Dim mysheet As New Excel.Worksheet
Set mybook = myexcel.Workbooks.Add '添加一个新的BOOK
Set mysheet = mybook.Worksheets.Add '添加一个新的SHEET
myexcel.Visible = False
mybook.Activate
mysheet.Range 1, 6
mysheet.Cells.CopyFromRecordset myrec
mybook.SaveAs (App.Path & "\123.xls") '保存文件
'mybook.SaveCopyAs (App.Path & "\123.slx") '保存文件
' myrec.Save (App.Path & "\1234.xls") '保存文件
myexcel.Quit