Results 1 to 7 of 7

Thread: TEXT to EXCEL

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 1999
    Location
    México, D.F.
    Posts
    84

    Arrow

    Hi Vb-World:

    I have a program that makes a report in text file, it has data like a table with colums and rows, i need to export it to Excel any version, how can i do that?, is there some API or function or method in VB to export from text to Excel?

    Thanks in advance.

    Best Regards.
    Angel Maldonado López.
    VB Programmer

  2. #2
    Hyperactive Member
    Join Date
    Nov 1999
    Location
    Leavenworth KS USA
    Posts
    482
    Probably the easiest way is to open your text file from Excel and then save your resultant spreadsheet as an Excel format. For the sake of learning a thing or two, before you open your text file report, put yourself in "record macro" mode. If you want to get really snooty, you could alternately use Data|Get External Data|Create New Query and use the text ISAM (if you have it installed). Hope this helps

  3. #3
    Randalf the Red honeybee's Avatar
    Join Date
    Jun 2000
    Location
    off others' brains
    Posts
    4,345

    Well ....

    Seems people are turning to VB-Office combination for a change!

    I have already tried to help one with VB-Word, am in the process of helping another with the same, and can do VB-Excel for you. The thing is I have to type out the entire code and mail it. This will take time, and you may have to wait for a week or so, as I do it from my home. I am picking up the samples from a book named something like 'Developing Client-Server Applications with VB 5'. There is an updated version of the book with VB 6. If you can get hold of that book, it will more than solve your problem. If not, mail me at [email protected] and wait for at least a week.

    I received thanks from the fellow, but I don't know whether it came from the heart or the mind (sincerely or politely!) I hope it is the former one.
    I am not a complete idiot. Some parts are still missing.
    Check out the rtf-help tutorial
    General VB Faq Thread
    Change is the only constant thing. I have not changed my signature in a long while and now it has started to stink!
    Get more power for your floppy disks. ; View honeybee's Elite Club:
    Use meaningfull thread titles. And add "[Resolved]" in the thread title when you have got a satisfactory response.
    And if that response was mine, please think about giving me a rep. I like to collect them!

  4. #4
    Lively Member
    Join Date
    May 2000
    Location
    London
    Posts
    99
    Format and save your file as a .csv Then if you open the file it will load into Excel.


    VB6 Enterprise sp5, SQL Server2000

  5. #5
    Hyperactive Member
    Join Date
    May 2000
    Location
    Or
    Posts
    316
    This is just off the top of my head, but the easiest way to do what you are thinking is to create you text file in a comma delimited format:

    ex. Header1,header2,header3,header4,
    data1,data2,data3,data4

    And save the text file with a .csv extension.

    And now if I remember right, to import this bad boy into excel, all you have to do is set a reference to the excel object library and then type in the following code (this only imports the data into an excel sheet and does nothing else, but once there, you can do much):

    Code:
    Dim ExcelApp as Excel.Application
    Dim ExcelBook as Excel.Workbook
    Dim ExcelSheet as Excel.WorkSheet
    
    Private sub CreateExcelObject(ByVal sFileName as string)
    
    Set ExcelApp=New Excel.Application
    Set ExcelBook=ExcelApp.workbooks.open(sFilename)
    'Set the active sheet.  This will be the object that you will call if you need to manipulate the worksheet.
    Set ExcelSheet=ExcelApp.ActiveSheet 
    
    End sub
    
    Private sub Command1_Click
    
    Call CreateExcelObjects(Text1.Text)
    ExcelApp.Visible=True
    
    End sub
    
    Private sub Form_Unload()
    
    'Set you objects equal to nothing, and close excel if you are doing all your work through code.
    
    ExcelApp.Quit
    
    'Here you might see Dialog boxes if you did not save before this.  You save using:
    
    'ExcelApp.SaveWorkSpace(Filename) 
    
    'I think.
    
    Set ExcelSheet=Nothing
    Set ExcelBook=Nothing
    Set ExcelApp=Nothing
    
    End sub
    Hope this helps.

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Jan 1999
    Location
    México, D.F.
    Posts
    84
    I want to thank to each one your post's, i take the frank and reeset solution, in fact i discover the meaning of .csv files and i can use the same way with tabs in a text files.

    Thanks again.

    Best regards.
    Angel Maldonado López.
    VB Programmer

  7. #7
    Lively Member
    Join Date
    May 2000
    Location
    London
    Posts
    99
    AM LOPEZ,

    .csv = Comma Separated Values

    as reeset wrote

    Header1,header2,header3,header4,
    data1,data2,data3,data4

    or

    "Header1","header2","header3","header4"
    "data1","data2","data3","data4"







    VB6 Enterprise sp5, SQL Server2000

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