Export data from Access to Excel
I am exporting data from Access to Excel with the following code:
Code:
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook 'Excel werkboek object
If Not IsExcelRunning (FUNCTION Checking if excel is open) Then
Set xlApp = CreateObject("Excel.Application")
Else
Set xlApp = GetObject(, "Excel.Application")
End If
xlApp.DisplayAlerts = False
Set xlBook = xlApp.Workbooks.Add()
xlBook.Sheets.Add
<DATA EXPORT LINES>
xlApp.DisplayAlerts = True
xlApp.Visible = True
Set xlBook = Nothing
Set xlApp = Nothing
Now when i execute this code it works fine till i execute it a second time after closing Excel. The first time Excel is show with data, the second time Excel opens also, but no data is shown. When i close Access and reopen it it works again one single time.
I already discovered that this happens ONLY when i use certain functions like Range. When i dont use them i dont have this problem.
By the way i am using Excel 2000 with VBA 6.0
Anyone know how to solve this? Did i forgot something?