CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2001
    Location
    Toronto, CANADA
    Posts
    16

    Convert Excel contents to CSV file

    Hello all you VB Gurus..

    I am writing a little utility that converts any excel file contents to a text file. I would want to be able to covert each cell in excel so that its content appears with a "quote" around it.

    Example: In Excel A1's content is Hello and B1's content is World, I would like the end product to look like "Hello", "World" in a text file. Is it possible for then to take the contents of the text file and send it as an email to a predefined recipient? How would I go about accomplishing this. I am a novice.. looking for code and a good explanation... hope you can help

    [n]Shaikh
    | http://nawedshaikh.com |

  2. #2
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: Convert Excel contents to CSV file

    Here is an example how to read the cell

    Dim xlsApp As Object
    dim s as string

    Set xlsApp = CreateObject("excel.application")
    xlsApp.Visible = False
    xlsApp.workbooks.Open "c:\MyPath\MyFile.XLS"

    s= """" & xlApp.Cells(1, 1) & """" ' that will add double quotes
    xlsApp.Close
    Set xlsApp = Nothing


    'That is the sample how to write to the text file

    Open "c:\temp\temp.txt" For Output As #1 'to write to
    Print #1, s
    Close #1

    Put everything into a loop and fill the text file




    Iouri Boutchkine
    [email protected]
    Iouri Boutchkine
    [email protected]

  3. #3
    Join Date
    Jun 1999
    Location
    England
    Posts
    86

    Re: Convert Excel contents to CSV file

    How about a simple way. Simply save the desired worksheet as a CSV file. Once you have done this you will find that the values do not have quotes around them as you wanted. Well you could then open the resulting file in VB and then write the contents back out again using the Write command.

    Why do it this way? You said you wanted to do this for any spreadsheet. If you do it this way Excel will only save those cells that have something in them. This will save an awful lot of programming.

    See how you get on you can always come back and ask for more help.

    Regards,
    Andy


  4. #4
    Join Date
    Mar 2001
    Location
    Toronto, CANADA
    Posts
    16

    Re: Convert Excel contents to CSV file

    Thanx for the NEW ideas... it is much clear now!

    1) When I was playing around with my app, i have a .mdb file that it creates in c:\temp, how would I create this mdb file so that if one already exists, it replaces it with the new one?

    [n]Shaikh
    | http://nawedshaikh.com |

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

Featured