MrExcel Message Board

Go Back   MrExcel Message Board > Question Forums > Excel Questions

Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only.

Reply
 
Thread Tools Display Modes
Old Mar 27th, 2002, 03:25 PM   #1
alanf
New Member
 
Join Date: Mar 2002
Posts: 6
Default

I need to convert some data I have in .xls format into .txt format. I also have to format it a certain way for a mail program that I have.

Here is how the data needs to be formatted:

[firstname],[lastname],[email]
"Alan","Smith","alan@aol.com"
"Tom","Jones","tomj@aol.com"
etc.

Does anyone know how to export this data and format it this way automatically?

Thanks,

Alan

[ This Message was edited by: alanf on 2002-03-27 14:49 ]
alanf is offline   Reply With Quote
Old Mar 27th, 2002, 03:29 PM   #2
Mark O'Brien
MrExcel MVP
 
Mark O'Brien's Avatar
 
Join Date: Feb 2002
Location: Columbus, OH, USA
Posts: 3,519
Default

Does the file have to be .txt? Could it have another extension like ".csv"? If it can then stick your data in columns A B and C then go to File|Save As and change the file type to Comma Separated Values (*.csv).


__________________
Mark O'Brien

Columbus Ohio Celtic Supporters Club
Mark O'Brien is offline   Reply With Quote
Old Mar 27th, 2002, 03:31 PM   #3
alanf
New Member
 
Join Date: Mar 2002
Posts: 6
Default

Yep. Unfortunately it has to be .txt format. You would think there would be a way to select export and then tell Excell what kind of seperators you want. I can't figure it out though.

Alan
alanf is offline   Reply With Quote
Old Mar 27th, 2002, 03:49 PM   #4
Yogi Anand
MrExcel MVP
 
Join Date: Mar 2002
Location: Michigan USA
Posts: 11,452
Default

Quote:
On 2002-03-27 14:25, alanf wrote:
I need to convert some data I have in .xls format into .txt format. I also have to format it a certain way for a new mail program that I have.

Here is how the data needs to be formatted:

[firstname],[lastname],[email]
"Alan","Smith","alan@aol.com"
"Tom","Jones","tomj@aol.com"
etc.

Does anyone know how to export this data and format it this way automatically?

Thanks,

Alan
Hi alanf:
Continuing with Mark's suggestion with saving data in your Excel worksheet as a CSV (comma delimited) format ...
after you have saved this file with the CSV extension, you can rename it with TXT extension.
I took your sample data, saved the data in CSV format and opened it in Notepad ... here is what I got:

first,last,email
Alan,Smith,alan@aol.com
Tom,Jones,tomj@aol.com

If you need to enclose the field headers in [] and you need to have each piece of data in double quotes, you may have some additional formatting to do.

HTH

Please post back if it works for you ... otherwise explain a little further and let us take it from there!
Yogi Anand is offline   Reply With Quote
Old Mar 27th, 2002, 03:52 PM   #5
alanf
New Member
 
Join Date: Mar 2002
Posts: 6
Default

Thanks HTH.

That is exactly what I need to do. Any idea of how to do the additional formatting? I don't necessarily have to add the [ ] around the headers. I can do that manually. It is going to be a pain to manually add " " around each item in the list...got any ideas?

Maybe i could user some formula or something to add the quotes around each item then convert it to .csv and then rename it to .txt? Anyone know a way to add " " around the text in each cell in an Excell document?

Alan

[ This Message was edited by: alanf on 2002-03-27 14:55 ]
alanf is offline   Reply With Quote
Old Mar 27th, 2002, 03:55 PM   #6
BabyTiger
Board Regular
 
Join Date: Mar 2002
Location: Wellington
Posts: 104
Default

Hi,

You might want to try the following:

Open "C:FileName.txt" For Output As #1
For i = 1 To 10
Print #1, """" & Range("A1").Offset(i - 1, 0).Value & """" & "," & _
"""" & Range("A1").Offset(i - 1, 1).Value & """" & "," & _
"""" & Range("A1").Offset(i - 1, 2).Value & """"
Next i
Close #1

The above code is assuming your column A is the first name, column B is surname, and column C is the E-mail Address.

HTH

PS. Yogi is too quick for me. But saving as .csv, and rename as .txt, the data in the file don't have the quotation marks.

[ This Message was edited by: BabyTiger on 2002-03-27 14:57 ]
BabyTiger is offline   Reply With Quote
Old Mar 27th, 2002, 03:59 PM   #7
alanf
New Member
 
Join Date: Mar 2002
Posts: 6
Default

What do I do with the code? Sorry I am a novice...don't know what to do with it.
alanf is offline   Reply With Quote
Old Mar 27th, 2002, 04:09 PM   #8
BabyTiger
Board Regular
 
Join Date: Mar 2002
Location: Wellington
Posts: 104
Default

Hi,

From the workbook/sheet that's got the list of name and e-mail address, select from menu bar, tools-macro-visual basic editor, and then from the microsoft visual basic screen, select from menu bar, insert module.

And then copy those codes to that module with an addition line before the code, "Sub Test()", and after code, enter "End Sub" in the line after.

Once you have done all that, you have setup your macro, and is ready to go.

Now make sure your data is in the right place. ie. First names are in the column A, Surnames are in column B, and e-mail addresses are in column C.

The codes in the previous post will not insert the headers, if your want to add that, then use the codes below:

Open "C:FileName.txt" For Output As #1
Print #1, "[firstname],[lastname],[email]"
For i = 1 To 10
Print #1, """" & Range("A1").Offset(i - 1, 0).Value & """" & "," & _
"""" & Range("A1").Offset(i - 1, 1).Value & """" & "," & _
"""" & Range("A1").Offset(i - 1, 2).Value & """"
Next i
Close #1

The difference is that extra line of code, that will add the headers to the txt file.

HTH
BabyTiger is offline   Reply With Quote
Old Mar 27th, 2002, 07:01 PM   #9
Yogi Anand
MrExcel MVP
 
Join Date: Mar 2002
Location: Michigan USA
Posts: 11,452
Default

Hi BabyTiger:
I tried the code in a sub -- Works ... Beautiful!
Yogi Anand is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT -4. The time now is 03:58 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
All contents Copyright 1998-2012 by MrExcel Consulting.
diabetic desserts recipes recipes Diabetic Soups Holiday Pizza Recipes Popcorn Recipes Recipes For Microwave Pasta Recipes Casserole Recipes Chili Recipes Curry Recipes Crockpot Recipes Apples Recipes Bread Recipes Vegetarian Recipes Vegetable recipes Desserts Recipes Appetizers Ethnic Recipes Meat Dishes Barbecue Recipes Sauces Recipes Marinade Recipes Low Fat Recipes Frugal Gourmet Kitchen Classics Recipes On The Grill Cook Books Seafood Recipes Cajun Recipes Breads Low Fat Low Fat Breads Bread Machine Recipes Yeast Breads Quick Breads Fat Free Vegetarian Salad Recipes Eggplant Recipes Radish Recipes Tomato Recipes Jalapeno Recipes Potato Recipes Lettuce Recipes Cabbage Recipes Beans Ambrosia Recipes Biscotti Recipes Desserts Low Fat Cookie Recipes Cheesecake Recipes Cake Recipes Pie Recipes Muffin Recipes Custard Recipes Best Appetizers Appetizers Low Fat Salsa Recipes Dip Recipes International Recipes Afghan Recipes Alaska Recipes French Recipes German Recipes Greek Recipes Italian Recipes Spanish Recipes Thai Recipes Korean Recipes Chinese Recipes Mexican Recipes Indian Recipes Beef Recipes Pork Pork & Ham Pork Butts Pork Chop Recipes Pork Ribs Rulled Pork Poultry Recipes Stews Recipes Ground Beef Barbecue Grill Barbecue Smoker All Purpose Sauce BBQ Sauce Barbecue Sauce Carolina BBQ Sauce Pickle Recipes Marinades Smoking Low Fat Appetizers & Dips Low Fat Breakfast Low Fat Cakes Low Fat Cheesecakes Low Fat Cookies Low Fat Desserts Low Fat Fish & Seafood Low Fat Meats Low Fat Pasta Low Fat Pies Low Fat Salads Low Fat Sandwiches Low Fat Sauces & Condiments Low Fat Sides Low Fat Soups Low Fat Vegetarian Baker's Dozen Taste of Home Recipe Book Bon Appetit Cookbook Blacktie Cookbook Buster Cook Book Cookbook USA Cook Book Cook Book Sara's Cookbook Sara's Cookbook Appetizers and Dips Poultry recipes Diabetic recipes Holiday recipes Miscellaneous recipes 110 recipes 1986 Usenet cookbook 2900 recipes Cyberrealm recipes Great sysops of world Specialty recipes Ceideburg recipes Cheese recipes Chili recipes Fruits recipes Garlic recipes Great chefs of NY Londontowne recipes Raisins recipes Recipes for kids US Food Vegetarian recipes Bread recipes Drinks Meat Dishes Brisket recipes Caribou recipes Chicken recipes Filet mignons recipes Pork recipes Swordfish recipes Turkey recipes Pasta recipes Uncategorized recipes Ethnic recipes Canada recipes English recipes Ethiopia recipes Germany recipes Greece recipes Mexican recipes Philippines recipes Welsh recipes Microwave recipes Soups recipes Vegetable recipes Asparagus recipes Barley recipes Brown rice recipes Lentil recipes Mushrooms recipes Salads recipes Wild rice Desserts recipes Cakes recipes Chocolate recipes Cookies recipes Ice cream recipes