Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default How to export a range to CSV

Hi

I am fairly new to VBA programming, however I feel confident that
something like this should be possible.

I want to create a script that exports a range selection in Excel 2007
to a CSV file (data.csv) using comma as field separator.

I have no problem making the selection and everything, my problem is
how to get the export working with the comma separator. My Excel uses
semicolon as default!

I really hope you can help me?

Thanks!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default How to export a range to CSV

You could create a macro that exports the data 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.)

Check out Earl's Text Write program first. It may do exactly what you want
right out of the box.

krumme wrote:

Hi

I am fairly new to VBA programming, however I feel confident that
something like this should be possible.

I want to create a script that exports a range selection in Excel 2007
to a CSV file (data.csv) using comma as field separator.

I have no problem making the selection and everything, my problem is
how to get the export working with the comma separator. My Excel uses
semicolon as default!

I really hope you can help me?

Thanks!


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default How to export a range to CSV

I think this code should work for you (assuming a rectangular selection),
just change the path in the Open statement to the directory location where
you want to put the Data.csv file...

Sub ExportSelectedRangeAsCSV()
Dim X As Long, FF As Long, R As Long, S() As String, StrOut As String
R = Selection.Rows.Count
ReDim S(1 To R)
For X = 1 To R
S(X) = Join(WorksheetFunction.Transpose(WorksheetFunction . _
Transpose(Selection.Rows(X).Value)), ",")
Next
StrOut = Join(S, vbNewLine)
FF = FreeFile
Open "c:\temp\Data.cvs" For Output As #FF
Print #FF, StrOut
Close #FF
End Sub

--
Rick (MVP - Excel)


"krumme" wrote in message
...
Hi

I am fairly new to VBA programming, however I feel confident that
something like this should be possible.

I want to create a script that exports a range selection in Excel 2007
to a CSV file (data.csv) using comma as field separator.

I have no problem making the selection and everything, my problem is
how to get the export working with the comma separator. My Excel uses
semicolon as default!

I really hope you can help me?

Thanks!


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default How to export a range to CSV

Actually, we can save a couple of lines and two variable...

Sub ExportSelectedRangeAsCSV()
Dim X As Long, FF As Long, S() As String
ReDim S(1 To Selection.Rows.Count)
For X = 1 To Selection.Rows.Count
S(X) = Join(WorksheetFunction.Transpose(WorksheetFunction . _
Transpose(Selection.Rows(X).Value)), ",")
Next
FF = FreeFile
Open "c:\temp\Data.cvs" For Output As #FF
Print #FF, Join(S, vbNewLine)
Close #FF
End Sub

--
Rick (MVP - Excel)


"Rick Rothstein" wrote in message
...
I think this code should work for you (assuming a rectangular selection),
just change the path in the Open statement to the directory location where
you want to put the Data.csv file...

Sub ExportSelectedRangeAsCSV()
Dim X As Long, FF As Long, R As Long, S() As String, StrOut As String
R = Selection.Rows.Count
ReDim S(1 To R)
For X = 1 To R
S(X) = Join(WorksheetFunction.Transpose(WorksheetFunction . _
Transpose(Selection.Rows(X).Value)), ",")
Next
StrOut = Join(S, vbNewLine)
FF = FreeFile
Open "c:\temp\Data.cvs" For Output As #FF
Print #FF, StrOut
Close #FF
End Sub

--
Rick (MVP - Excel)


"krumme" wrote in message
...
Hi

I am fairly new to VBA programming, however I feel confident that
something like this should be possible.

I want to create a script that exports a range selection in Excel 2007
to a CSV file (data.csv) using comma as field separator.

I have no problem making the selection and everything, my problem is
how to get the export working with the comma separator. My Excel uses
semicolon as default!

I really hope you can help me?

Thanks!



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
Export range to XML? fedude Excel Programming 0 March 10th 08 11:06 AM
export range as picture manolo Excel Programming 1 October 13th 05 10:17 PM
Export range to text file martin Excel Programming 2 August 30th 04 06:39 PM
How to export a range to a picture ? Ayato[_8_] Excel Programming 2 June 13th 04 03:10 AM
Export range to html Mikel Perez Excel Programming 0 December 1st 03 03:54 PM


All times are GMT +1. The time now is 09:01 AM.

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

About Us

"It's about Microsoft Excel"