# OLE + Excel problem



## haxor (25. Mai 2004)

Hallo, ich habe hier folgender code, der den inhalt eines recordset in die exeltabelle einfügt: 


```
Public Function Export2XL(InitRow As Long) As Long 

Dim MyIndex As Integer                            'Used for Index 
Dim MyRecordCount As Long                    'Store the number of record on the table 
Dim MyFieldCount As Integer                    'Store the number of fields or column 
Dim ApExcel As Object                             'To open Excel 
Dim MyCol As String 
Dim Response As Integer 

Set ApExcel = CreateObject("Excel.application")  'Creates an object 
Set rs = m_pRSComponents.Clone 

ApExcel.Visible = True                                       'This enable you to see the process in Excel 
ApExcel.Workbooks.Add                                   'Adds a new book. 


MyFieldCount = rs.Fields.Count 

'Fill the first line with the name of the fields 
For MyIndex = 0 To MyFieldCount - 1 
    ApExcel.Cells(InitRow, (MyIndex + 1)).Formula = rs.Fields(MyIndex).Name   'Write Title to a Cell 
    ApExcel.Cells(InitRow, (MyIndex + 1)).Font.Bold = True 
    ApExcel.Cells(InitRow, (MyIndex + 1)).interior.colorindex = 36 
    ApExcel.Cells(InitRow, (MyIndex + 1)).WrapText = True 
Next 

'Draw border on the title line 
MyCol = Chr((64 + MyIndex)) & InitRow 
ApExcel.Range("A" & InitRow & ":" & MyCol).Borders.Color = RGB(0, 0, 0) 
MyRecordCount = 1 + InitRow 

'Fill the excel book with the values from the database 
Do While rs.EOF = False 
For MyIndex = 1 To MyFieldCount 
    ApExcel.Cells(MyRecordCount, MyIndex).Formula = rs((MyIndex - 1)).Value     'Write Value to a Cell 
    ApExcel.Cells(MyRecordCount, MyIndex).WrapText = False 'Format the Cell 
Next 
    MyRecordCount = MyRecordCount + 1 
    rs.MoveNext 
    If MyRecordCount > 50 Then 
        Exit Do 
    End If 
Loop 


End Function
```


in diesem fall wird das excel file geöffnet. 
ich möchte aber das excel file ein ein OLE anzeigen lassen. wie kriege ich das jetzt hin?


----------

