Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 106
Default Creating CSV Comma Delimited File



I am using the following code to create a CSV file for a sheet within a
workbook. I have posted the CSV file that gets created and there are 2
problems with the file. The first is that there is an extra comma
placed at the end of each row. In some cases the comma is there, and
in other cases it is not there (although for the sample I've provided
the extra column is there for each row). Secondly, there is a group of
commas at the end of the file. I think this situation can be
eliminated if I specify the actual range for which I want to create the
CSV file. Does anyone know the syntax for that?

Thanks. Connie

' Create CSV file for Technicians
Sheets("Field Rep Time Sheet").Select
Directory = CurDir
FName = "\Upload Tech " & Format(Now(), "yyyymmmddhhmm")
FileName = Trim(Directory) + Trim(FName)
Sheets("Upload Data Tech").Copy
Set wb = ActiveWorkbook
wb.SaveAs FileName & ".csv", FileFormat:=xlCSV
wb.Close SaveChanges:=False
MsgBox "Upload File Saved for TECHNICIANS"




Here is the data in the worksheet. The last column is column O and is
either 20 or 0.

EndDate EmployeeName OracleID TechNo TotalHours TrainingHours TechOffice VacationHours VacationEndDate BereavementHours JuryDutyHours ClericalHours WarehouseHours TotalHours PerDiem
10/7/2006 Michael
Albert 23709 1234 7.00 4.00 0.00 0.00 0.00 0.00 0.00 0.00 11.00 20
10/12/2006 Michael
Albert 23709 1234 1.92 0.00 4.10 5.70 10/12/2006 0.00 0.00 0.00 0.00 11.72 0
10/13/2006 Michael
Albert 23709 1234 0 1.916666667 4.1 0 5.466666667 0 0 0 11.48333333 0
10/7/2006 Michael Albert 23709 1234 7 4 0 0 0 0 0 0 11 20
10/8/2006 Michael Albert 23709 1234 5.85 0 4.1 0 0 0 0 0 9.95 0





Here is the data in the CSV file. Notice that there is an extra comma
at the end of each row, and there are commas at the end of the file.
The commas at the end of the file actually extend to I believe 65000
rows.

EndDate,EmployeeName,OracleID,TechNo,TotalHours,Tr ainingHours,TechOffice,VacationHours,VacationEndDa te,BereavementHours,JuryDutyHours,ClericalHours,Wa rehouseHours,TotalHours,PerDiem,,
10/7/2006,Michael
Albert,23709,1234,7.00,4.00,0.00,0.00,,0.00,0.00,0 .00,0.00,11.00,20,,
10/12/2006,Michael
Albert,23709,1234,1.92,0.00,4.10,5.70,10/12/2006,0.00,0.00,0.00,0.00,11.72,0,,
10/13/2006,Michael
Albert,23709,1234,0,1.916666667,4.1,0,,5.466666667 ,0,0,0,11.48333333,0,,
10/7/2006,Michael Albert,23709,1234,7,4,0,0,,0,0,0,0,11,20,,
10/8/2006,Michael Albert,23709,1234,5.85,0,4.1,0,,0,0,0,0,9.95,0,,
,,,,,,,,,,,,,,,,
,,,,,,,,,,,,,,,,
,,,,,,,,,,,,,,,,
,,,,,,,,,,,,,,,,
,,,,,,,,,,,,,,,,
,,,,,,,,,,,,,,,,
,,,,,,,,,,,,,,,,
,,,,,,,,,,,,,,,,
,,,,,,,,,,,,,,,,
,,,,,,,,,,,,,,,,
,,,,,,,,,,,,,,,,

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Creating CSV Comma Delimited File

You may be able to eliminate the lines with just commas on it by resetting the
used range.

Visit Debra Dalgleish's site for some techniques for resetting that
lastusedcell.
http://www.contextures.com/xlfaqApp.html#Unused

Or you could copy just the data to a worksheet in a new workbook and save that
new workbook as a .csv file.

But I think that the commas at the end of the line are beyond your control if
you use .saveas.

Saved from a previous post:

This might describe the problem of too many commas in CSV files:

http://support.microsoft.com/default.aspx?scid=77295
Column Delimiters Missing in Spreadsheet Saved as Text

(It actually describes missing delimiter, but if some are "missing", maybe the
ones appearing are "extra".)

(But a lot of programs (excel included) don't care about those extra columns.
Maybe you don't have to care, either???)

Maybe you could write your own exporting program that would behave exactly the
way you want:

Here are three sites that you could steal some code from:

Earl Kiosterud's Text Write program:
www.smokeylake.com/excel
(or directly: http://www.smokeylake.com/excel/text_write_program.htm)

Chip Pearson's:
http://www.cpearson.com/excel/imptext.htm

J.E. McGimpsey's:
http://www.mcgimpsey.com/excel/textfiles.html

(or maybe you could build your own formula and copy|paste into Notepad.)

==============
Take a look at Earl's program. I bet it does what you want.

Connie wrote:

I am using the following code to create a CSV file for a sheet within a
workbook. I have posted the CSV file that gets created and there are 2
problems with the file. The first is that there is an extra comma
placed at the end of each row. In some cases the comma is there, and
in other cases it is not there (although for the sample I've provided
the extra column is there for each row). Secondly, there is a group of
commas at the end of the file. I think this situation can be
eliminated if I specify the actual range for which I want to create the
CSV file. Does anyone know the syntax for that?

Thanks. Connie

' Create CSV file for Technicians
Sheets("Field Rep Time Sheet").Select
Directory = CurDir
FName = "\Upload Tech " & Format(Now(), "yyyymmmddhhmm")
FileName = Trim(Directory) + Trim(FName)
Sheets("Upload Data Tech").Copy
Set wb = ActiveWorkbook
wb.SaveAs FileName & ".csv", FileFormat:=xlCSV
wb.Close SaveChanges:=False
MsgBox "Upload File Saved for TECHNICIANS"

Here is the data in the worksheet. The last column is column O and is
either 20 or 0.

EndDate EmployeeName OracleID TechNo TotalHours TrainingHours TechOffice VacationHours VacationEndDate BereavementHours JuryDutyHours ClericalHours WarehouseHours TotalHours PerDiem
10/7/2006 Michael
Albert 23709 1234 7.00 4.00 0.00 0.00 0.00 0.00 0.00 0.00 11.00 20
10/12/2006 Michael
Albert 23709 1234 1.92 0.00 4.10 5.70 10/12/2006 0.00 0.00 0.00 0.00 11.72 0
10/13/2006 Michael
Albert 23709 1234 0 1.916666667 4.1 0 5.466666667 0 0 0 11.48333333 0
10/7/2006 Michael Albert 23709 1234 7 4 0 0 0 0 0 0 11 20
10/8/2006 Michael Albert 23709 1234 5.85 0 4.1 0 0 0 0 0 9.95 0

Here is the data in the CSV file. Notice that there is an extra comma
at the end of each row, and there are commas at the end of the file.
The commas at the end of the file actually extend to I believe 65000
rows.

EndDate,EmployeeName,OracleID,TechNo,TotalHours,Tr ainingHours,TechOffice,VacationHours,VacationEndDa te,BereavementHours,JuryDutyHours,ClericalHours,Wa rehouseHours,TotalHours,PerDiem,,
10/7/2006,Michael
Albert,23709,1234,7.00,4.00,0.00,0.00,,0.00,0.00,0 .00,0.00,11.00,20,,
10/12/2006,Michael
Albert,23709,1234,1.92,0.00,4.10,5.70,10/12/2006,0.00,0.00,0.00,0.00,11.72,0,,
10/13/2006,Michael
Albert,23709,1234,0,1.916666667,4.1,0,,5.466666667 ,0,0,0,11.48333333,0,,
10/7/2006,Michael Albert,23709,1234,7,4,0,0,,0,0,0,0,11,20,,
10/8/2006,Michael Albert,23709,1234,5.85,0,4.1,0,,0,0,0,0,9.95,0,,
,,,,,,,,,,,,,,,,
,,,,,,,,,,,,,,,,
,,,,,,,,,,,,,,,,
,,,,,,,,,,,,,,,,
,,,,,,,,,,,,,,,,
,,,,,,,,,,,,,,,,
,,,,,,,,,,,,,,,,
,,,,,,,,,,,,,,,,
,,,,,,,,,,,,,,,,
,,,,,,,,,,,,,,,,
,,,,,,,,,,,,,,,,


--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Weird File Open/Save As Behavior [email protected] Excel Discussion (Misc queries) 0 December 9th 05 02:26 AM
how to save a file as ASCII: expanded comma delimited text (.exp). kmh Excel Discussion (Misc queries) 0 May 1st 05 01:05 AM
Creating a PDF file programatically from Excel Chaplain Doug Excel Discussion (Misc queries) 0 December 16th 04 08:49 PM
.CSV file format - comma or semi-colon? bavjean Excel Worksheet Functions 5 November 12th 04 12:26 PM
.CSV file format - comma or semi-colon antifashionpimp Excel Worksheet Functions 1 November 10th 04 01:18 PM


All times are GMT +1. The time now is 10:04 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"