saving to .csv and preserving numbers as text

  • Thread starter Thread starter Bill Strickland
  • Start date Start date
B

Bill Strickland

I am trying to export from Excel to .csv and want to
preserve data such as "1100.000" just as it is without
loosing any digits. Any ideas?
 
Bill,

This should work! I realize you posted in .misc, but a macro is all I could
come up with!

Sub ExportCSV()
Dim fs, f
OutFile = Application.GetSaveAsFilename(FileFilter:="CSV (Comma
delimited)(*.csv), *.csv")
If OutFile = False Then Exit Sub
ActiveSheet.UsedRange.Select
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.OpenTextFile(OutFile, 2, -2)
For Rcount = 1 To Selection.Rows.Count
For CCount = 1 To Selection.Columns.Count
Outline = CStr(Selection.Cells(Rcount, CCount).Text)
f.Write Outline
If CCount <> Selection.Columns.Count Then f.Write ", "

Next
f.Write vbCrLf
Next
f.Close
Set f = Nothing
Set fs = Nothing
End Sub

Watch out for text wrapping everything but Sub and End Sub are tabbed out.

If you are unfamiliar with VBA David McRitchie has instructions at
http://www.mvps.org/dmcritchie/excel/getstarted.htm

Dan E
 
Back
Top