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' Add a new BOOK
Set mysheet = mybook. Worksheets. add' Add a new SHEET.
Myexcel. Visible = False
Mybook. Activate
Mysheet. Range 1, 6
Mysheet. Cells. CopyFromRecordset myrec
Mybook. SaveAs (App. Path & "\ 123.xls") 'save the file
'Mybook. SaveCopyAs (App. Path & "\ 123.slx") 'to save the file
'Myrec. Save (App. Path & "\ 1234.xls") 'to Save the file
Myexcel. Quit