Private Sub Command6_Click() Dim xlApp As Excel.Application Dim xlBook As Excel.Workbook Dim xlSheet As Excel.Worksheet Dim strFile As String Dim i As Integer Dim j As Integer Set xlApp = CreateObject("Excel.Application") '创建Application对象 Set xlBook = xlApp.Workbooks.Add Set xlSheet = xlBook.ActiveSheet '活动Sheet付值给xlSheet With MSFlexGrid1 For i = 0 To .Rows - 1 .Row = i For j = 0 To .Cols - 1 .Col = j xlSheet.Cells(i + 1, j + 1) = .Text Next j Next i i = 4
End With strFile = App.Path & "\test3.xls" xlSheet.SaveAs strFile Set xlSheet = Nothing xlBook.Close Set xlBook = Nothing xlApp.Quit Set xlApp = NothingEnd Sub
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Dim strFile As String Dim i As Integer
Dim j As Integer
Set xlApp = CreateObject("Excel.Application") '创建Application对象 Set xlBook = xlApp.Workbooks.Add
Set xlSheet = xlBook.ActiveSheet '活动Sheet付值给xlSheet With MSFlexGrid1
For i = 0 To .Rows - 1
.Row = i
For j = 0 To .Cols - 1
.Col = j
xlSheet.Cells(i + 1, j + 1) = .Text
Next j
Next i
i = 4
End With strFile = App.Path & "\test3.xls" xlSheet.SaveAs strFile
Set xlSheet = Nothing
xlBook.Close
Set xlBook = Nothing
xlApp.Quit
Set xlApp = NothingEnd Sub