Save .txt file to .csv in VBA

L

lliang27

Hi List,

User has 4 CSV format files. Since there are extra spaces in the files
when open them from Excel, they have to open each of them using NotePad
and delete the extra spaces. They can't do this from CSV file directly.
If they deleted the extra empty column from Excel, and open it again
with NotePad, the " " will disappear.

They want these steps can be handle using a macro, so they don't need
to manually open each file and delete the spaces.

What I did:

I open csv file as input, use trim(string) to get rid of the extra
spaces. then i write each row to a .txt file.

if i open the txt file using NotePad then do SaveAs to a csv file. it
works fine. when user reviewing it from NotePad, they still see " "
around each field. But my question is, how can I accomplish this step
using VBA?

I tried to open the txt file from Excel and save it as .csv file, when
i open the .csv file from NotePad, all the quotes were gone.

I have posted my questions for a couple of days, but didn't get any
answers so far. Please, if anyone has any idea, please let me know.

Thanks so much.
 
J

JE McGimpsey

L

lliang27

Thanks for your reply.

I can finish the steps to create a txt file with quotes around each
fields. But eventually user needs each file with the extension .csv. So
I tried to open .txt from Excel then save it to .csv, however, if user
view the .csv file with notepad, all quotes are gone. But if i open the
..txt file from notepad, then do a saveas to a .csv format, then review
the new .csv file from notepad, i got the result user wants to see -
quotes with each filed. for example,

"Name", "Street", "City", "State",

But how can i make this a macro step for user?

Please help.

Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top