Try this:
Option Explicit
Dim objExcel As Excel.Application
Dim objWorkbook As Excel.Workbook
Private Declare Function ShellExecute Lib "shell32.dll" Alias _
"ShellExecuteA" (ByVal HWnd As Long, ByVal lpOperation _
As String, ByVal lpFile As String, ByVal lpParameters _
As String, ByVal lpDirectory As String, ByVal nShowCmd _
As Long) As Long
Private Sub Command1_Click()
Dim i As Long
Dim n As Long
On Error Resume Next
Set objExcel = GetObject(, "Excel.Application"

If Err.Number Then
Err.Clear
Set objExcel = CreateObject("Excel.Application"

If Err.Number Then
MsgBox "Can't open Excel."
End If
End If
objExcel.Visible = True
Set objWorkbook = objExcel.Workbooks.Add
AppActivate "FlexGrid To Excel Demo"
For i = 0 To 3
MSFlexGrid1.Row = i
For n = 0 To 3
MSFlexGrid1.Col = n
objWorkbook.ActiveSheet.Cells(i + 1, n + 1).Value = MSFlexGrid1.Text
Next
Next
End Sub
Private Sub Form_Load()
Dim i As Integer
Dim n As Integer
Me.Caption = "FlexGrid To Excel Demo"
'Populate the FlexGrid with sample data
With MSFlexGrid1
.Rows = 1
.Cols = 4
'Add field headers
For i = 1 To 3
.Col = i
.Text = "Heading " & i
Next
'Add data
For i = 1 To 3
.Rows = .Rows + 1
.Row = .Rows - 1
.Col = 0
.Text = "Record " & i
For n = 1 To 3
.Col = n
.Text = "Row " & i & ",Col " & n
Next
Next
End With
End Sub
Private Sub Form_Unload(Cancel As Integer)
Set objWorkbook = Nothing
Set objExcel = Nothing
End Sub