Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 26th, 2007, 09:40 AM
Authorized User
 
Join Date: Jul 2007
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.


 
Old July 26th, 2007, 09:46 AM
Friend of Wrox
 
Join Date: Oct 2004
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
 
Old July 26th, 2007, 12:11 PM
Authorized User
 
Join Date: Jul 2007
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.




 
Old July 26th, 2007, 02:09 PM
Authorized User
 
Join Date: Jul 2007
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

thanks







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





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.