Saveas csv produces different file sizes

njbeancounter

Board Regular
Joined
Oct 7, 2002
Messages
158
Hi all...

So my macro to saveas csv finally works!

However, the reason I need a csv file is to load the data into an ADP system.

The saved file does not load properly, BUT, if the data is copied and pasted to a new file, and saved as a csv file, the import then works.

The one oddity that I can see is that the macro saved file is slightly larger than the re-saved file.

On the surface, both appear to have identical data.

I didnt come this far to have to open the file, copy the data, and save the file again...kinda defeats the purpose, right?

Any suggestions would be appreciated

Steve
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
First suggestion would be to post your code, so we can see exactly what it is doing.
Without seeing that, we can only guess as to what the problem might be.
 
Upvote 0
Joe...Fair point...ty

Sub savesllc()
'
Dim llcname As String

llcname = Sheets("main").Range("llcname")

'copies the range llcems to a new file

Application.Goto reference:="llcems"
Selection.Copy
Workbooks.Add
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False

' saves the new file

ChDir "C:\Users\stephenm\Documents\Steve\ADP\EMS"
ActiveWorkbook.SaveAs Filename:=llcname, FileFormat:=xlCSV

'closes current file
ActiveWorkbook.Close

Application.Goto reference:="home"

End Sub
 
Upvote 0
Can you compare the original exported file to the newly copied/saved one to see if there are any differences (I am guessing there will be, as you said the files are not the same size)?
You will want to do this comparison in a Text Editor program (like NotePad, WordPad, or some other Text Editor), and not Excel.

A few of the things to look for is:
1. Has the length of any of the rows changed? If so, what changed? Culprits could be something like leading zeroes from certain fields being dropped, date formats changing, or number formats changing.
2. Do both files end in the same place on the same row? Does one have a carriage return at the end, and the other doesn't?
 
Upvote 0
Now I see why you are an MVP Joe...

Opening the files in Notepad revealed leading zeroes in the employee id in one file, but not the other.

I wish I posted here sooner!

Thank you
Steve
 
Upvote 0
You are welcome!

I have had lots of experience working with data files. One of my biggest "pet peeves" is that Microsoft deemed Excel as the default program to open CSV files. This often leads to "bad" results, as opening the CSV file in Excel may actually do some conversions on the data, like dropping zeroes, changing date & numeric formats, etc. If you truly want to see what is contained in a CSV file (without anything being altered along the way), you need to use a Text Editor to view it, and not Excel.

One of the first things I do when I get a new computer is go into the file association settings, and change it so that Excel is not the default program to open CSV files.
 
Upvote 0

Forum statistics

Threads
1,214,586
Messages
6,120,402
Members
448,958
Latest member
Hat4Life

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top