Click to See Complete Forum and Search --> : Convert Excel contents to CSV file


Nawed
June 24th, 2001, 11:40 PM
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 |

Iouri
June 25th, 2001, 07:02 AM
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
iouri@hotsheet.com

Andyb
June 25th, 2001, 03:04 PM
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

Nawed
June 25th, 2001, 11:41 PM
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 |