G
GeorgeAtkins
I have an xls 2003 file with dates, text and currency values. I need to run a
macro to export to a CSV format. When run, the currency values convert to
text. I've tried various "pastespecial" options. But when I get the currency
to show up as numbers, the dates show up unformatted as integers, too.
Here is a sample of the Excel data:
1/3/2005 5.03.h.1 District 287 $65,658 Carl Perkins Grant
1/3/2005 5.03.h.2 District 287 $7,525 Tech Prep Grant
Here is what it looks like after a typical "pastespecial":
1/3/2005,5.03.h.1, 287,"$65,658",Carl Perkins Grant
1/3/2005,5.03.h.2, 287,"7,525",Tech Prep Grant
Here is my code:
Sub ExportToCSV()
' Save selected range as a CSV text file
Dim ThisBook As Workbook
ChDrive "S"
ChDir "S:\TECH\GEORGE\"
Set ThisBook = ActiveWorkbook
Selection.Copy
Workbooks.Add
Selection.PasteSpecial Paste:=xlPasteValues ' one of several options used
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:="TestForRichard.txt", FileFormat:=xlCSV
ActiveWorkbook.Close
Application.DisplayAlerts = True
ThisBook.Activate
End Sub
By the way, the exact range can change, meaning that the columns are NOT
always in the positions shown!
Thanks for any ideas or a thwack on the head for overlooking something
obvious.
George
macro to export to a CSV format. When run, the currency values convert to
text. I've tried various "pastespecial" options. But when I get the currency
to show up as numbers, the dates show up unformatted as integers, too.
Here is a sample of the Excel data:
1/3/2005 5.03.h.1 District 287 $65,658 Carl Perkins Grant
1/3/2005 5.03.h.2 District 287 $7,525 Tech Prep Grant
Here is what it looks like after a typical "pastespecial":
1/3/2005,5.03.h.1, 287,"$65,658",Carl Perkins Grant
1/3/2005,5.03.h.2, 287,"7,525",Tech Prep Grant
Here is my code:
Sub ExportToCSV()
' Save selected range as a CSV text file
Dim ThisBook As Workbook
ChDrive "S"
ChDir "S:\TECH\GEORGE\"
Set ThisBook = ActiveWorkbook
Selection.Copy
Workbooks.Add
Selection.PasteSpecial Paste:=xlPasteValues ' one of several options used
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:="TestForRichard.txt", FileFormat:=xlCSV
ActiveWorkbook.Close
Application.DisplayAlerts = True
ThisBook.Activate
End Sub
By the way, the exact range can change, meaning that the columns are NOT
always in the positions shown!
Thanks for any ideas or a thwack on the head for overlooking something
obvious.
George