I'm trying to export data from my database to a text file and then open it with Excel. I'm going through the text file because I have about 65,000 records to export. The problem is that the close statement doesn't save all of the last string to the file. Only exiting the application saves this data, but by the time I exit, Excel is already missing the data too. How can I get the rest of the data saved before Excel opens it? Here's the code that I'm using.

Open "C:\Test.txt" For Output As #FreeFile

'Put the data in the temporary file
Do Until rsReport.EOF = True
strOutput = [Several strings from the rdoResultset, delimited by vbtab]
Print #FileNumber, strOutput
DoEvents
rsReport.MoveNext
Loop

DoEvents

Close #FreeFile
rsReport.Close

Dim oExcel As Object
Dim oBook As Object
Dim oSheet As Object

'Open the file with Excel.
Set oExcel = CreateObject("Excel.Application")
Set xlBook = oExcel.Workbooks.Open("C:\Test.txt")

'Save the file.
DoEvents
xlBook.SaveAs filename:=GenFile & ".xls" _
, FileFormat:=xlExcel9795, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False