I see many people asking how to export a VB6 MSFlexgrid to an Excel workbook....this short code with a couple of simple For-Loops is an easy way to do it (Make sure you have a REFERENCE to MS Excel in your project).
Code:
Private Sub smnuExportExcel_Click()
Dim oExcel As excel.Application
Dim oWb As excel.Workbook
Dim oSheet As excel.Worksheet
Dim x As Integer
Dim y As Integer
Set oExcel = New excel.Application
Set oExcel = CreateObject("Excel.Application")
Set oWb = oExcel.Workbooks.Add
Set oSheet = oWb.Worksheets("Sheet1")
With oSheet
For x = 0 To flexgrid1.Rows - 1
For y = 0 To 6
.Cells(x + 1, y + 1) = flexgrid1.TextMatrix(x, y) 'Note, "x + 1" as Excel refers to rows and columns beginning with 1, whereas VB6's flexgrids start with 0.
Next y
Next x
oWb.SaveAs FileName:=App.Path & "\myExcelFile.xlsx"
oExcel.Visible = True
Set oWb = Nothing
Set oExcel = Nothing
End Sub