Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 26th, 2007, 09:40 AM
Authorized User
 
Join Date: Jul 2007
Location: , , .
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Default Converting Excel file into a text file

Hi,

How could I convert/save an excel file into a text file using macro.

Data in my Excel file has 40 to 50 rows and 15 to 20 columns.

Like below

`P` 2 02-MAY-07 02-MAY-07 `USD` -1 `A`
`P` 2 02-MAY-07 02-MAY-07 `USD` -1 `A`
`P` 2 02-MAY-07 02-MAY-07 `USD` -1 `A`

I like put a comma after each cell except last one of each row and and save the data into a text file.

`P`, 2, 02-MAY-07, 02-MAY-07, `USD`, -1, `A`
`P` 2, 02-MAY-07, 02-MAY-07, `USD`, -1, `A`
`P` 2, 25-JUL-07, 25-JUL-07, `USD`, -1, `A`

Thanks for your valuable time.


Reply With Quote
  #2 (permalink)  
Old July 26th, 2007, 09:46 AM
Friend of Wrox
 
Join Date: Oct 2004
Location: Clinton, UT, USA.
Posts: 564
Thanks: 0
Thanked 4 Times in 4 Posts
Default

The easist way to do things like this, is to select 'Record a New Macro' from the tools menu, and then perform the task.

In this case, I just did a Save As, and selected CSV (MS-DOS) as the file type.

The code which it generated for the Macro was:

    ChDir "C:\Documents and Settings\mmackrory\Desktop"
    ActiveWorkbook.SaveAs Filename:= _
        "C:\Documents and Settings\user\Desktop\Training.csv", FileFormat:= _
        xlCSVMSDOS, CreateBackup:=False

Hope that helps,

Mike

Mike
EchoVue.com
Reply With Quote
  #3 (permalink)  
Old July 26th, 2007, 12:11 PM
Authorized User
 
Join Date: Jul 2007
Location: , , .
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Default


Thanks Mike,
That works great.
But I am looking just straight text (MS-dos) format.
I don't want automatically put comma (,) by system which actually
.CSV does.

Let me know if you have any other thought.




Reply With Quote
  #4 (permalink)  
Old July 26th, 2007, 02:09 PM
Authorized User
 
Join Date: Jul 2007
Location: , , .
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Mike,
that works fine when I use
FileFormat:= xlMSDOS,

thanks


Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
importing text file into excel stealthdevil Excel VBA 2 July 10th, 2007 11:28 AM
Importing text file into excel anamarijaf Excel VBA 4 January 27th, 2007 05:50 AM
Transferring data from text file to Excel imranshah Excel VBA 0 July 5th, 2006 10:22 AM
Converting excel file into XML... muskaanbajaj ASP.NET 1.0 and 1.1 Professional 3 April 3rd, 2006 12:33 PM
How to Covert Excel to Text file as Database narendra_patil ASP.NET 1.x and 2.0 Application Design 1 July 20th, 2005 03:01 PM



All times are GMT -4. The time now is 05:30 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.