9月 072013
 

注意:下記のコードはVB6.0に適応する
[vb]
Public Function savetoxls(ByVal dd As Adodc) ‘Save the data from Adodc to Excel
Dim ee As String
Dim i As Integer
ee = "ouput asi.xls"

Dim myexcel As New Excel.Application
Dim mybook As New Excel.Workbook
Dim mysheet As New Excel.Worksheet
Set mybook = myexcel.Workbooks.Add
Set mysheet = mybook.Worksheets.Add
myexcel.Visible = True
mysheet.Cells.CopyFromRecordset dd.Recordset
mysheet.Range("A1").Select
myexcel.Selection.EntireRow.Insert
mysheet.Range("a1").Select

For i = 0 To dd.Recordset.Fields.Count – 1
myexcel.ActiveCell.FormulaR1C1 = dd.Recordset.Fields(i).Name
mysheet.Range(Chr(66 + i) & "1").Select
Next i
mybook.SaveAs (App.Path & "" & ee)
End Function
[/vb]

 Tagged with: