Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
| 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 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
  #1 (permalink)  
Old July 3rd, 2007, 04:34 AM
Authorized User
 
Join Date: Mar 2007
Location: , , .
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default Change excel into csv format

I have a excel file with 30 worksheets (naming 1, 2, 3, ..., 29, 30)
Can I change each worksheet into one CSV file by marco?

*Sometimes the worksheet name may be random but still inside 1-30 range

Thanks

  #2 (permalink)  
Old July 3rd, 2007, 04:51 AM
Friend of Wrox
Points: 3,060, Level: 23
Points: 3,060, Level: 23 Points: 3,060, Level: 23 Points: 3,060, Level: 23
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2005
Location: , , .
Posts: 812
Thanks: 1
Thanked 53 Times in 49 Posts
Default

You cannot convert all sheets into one Excel directly

You convert each sheet into CSV using the following

i1 = 1
For Each SHT In Sheets
    SHT.Activate
    ActiveWorkbook.SaveAs "C:\Temp" & i1 & ".csv", xlCSV
    i1 = i1 + 1
Next SHT


Then use the following code to collate all to a single file

Sub Append_Text_Files()

Dim oFS As FileSystemObject
Dim oFS1 As FileSystemObject

Dim oTS As TextStream
Dim oTS1 As TextStream

Dim vTemp

Set oFS = New FileSystemObject
Set oFS1 = New FileSystemObject


For i1 = 1 To 30

    Set oTS = oFS.OpenTextFile("c:\Sheet" & i1 & ".txt", ForReading)
    vTemp = oTS.ReadAll

    Set oTS1 = oFS.OpenTextFile("c:\Documents and Settings\160831\Temp.txt", ForAppending, True)
    oTS1.Write (vTemp)

Next i1

End Sub

You need to add the microsoft scripting runtime reference to use the above code

Good luck
Shasur

http://www.dotnetdud.blogspot.com
  #3 (permalink)  
Old July 4th, 2007, 01:10 PM
Authorized User
 
Join Date: Mar 2007
Location: , , .
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Shasur,

I try to open the csv file in notepad and i saw the spacing become comma, can i remove the comma?

Thanks again

  #4 (permalink)  
Old July 5th, 2007, 01:09 AM
Friend of Wrox
Points: 3,060, Level: 23
Points: 3,060, Level: 23 Points: 3,060, Level: 23 Points: 3,060, Level: 23
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2005
Location: , , .
Posts: 812
Thanks: 1
Thanked 53 Times in 49 Posts
Default

You can retain those spaces. That shouldn't be a problem



http://www.dotnetdud.blogspot.com
  #5 (permalink)  
Old July 5th, 2007, 02:02 AM
Authorized User
 
Join Date: Mar 2007
Location: , , .
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks shasur.

All the empty cell in excel become comma by the marco
and I want to eliminate the comma in A1:o10 in everysheet.
the other remain unchange






Similar Threads
Thread Thread Starter Forum Replies Last Post
count the string from csv format sudhirbharti C# 1 March 25th, 2008 03:16 PM
Change the format of MS Excel Cells from MS Access hewstone999 Access VBA 0 March 7th, 2008 07:19 AM
Save a file in CSV format thru Excel VBA macro roli2712 Excel VBA 1 July 11th, 2007 03:05 AM
Is there a component to change file to csv format? greatProject ADO.NET 0 November 11th, 2004 12:20 PM
exporting to csv format dazednconfused Beginning PHP 1 July 11th, 2003 03:31 PM





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