Results 1 to 2 of 2

Thread: Closing File doen't save all the data

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 1999
    Location
    Cookeville, Tn 38501
    Posts
    39

    Closing File doen't save all the data

    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

  2. #2
    Gerco
    Guest
    Have you tried waiting for a few seconds before starting Excel? Perhaps the OS needs a bit of time to save the data, but Excel already needs it by then.

    Try to wait a second or two before starting, or use a button or something like that.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width