save as worksheets as csv files

T

tonyb

Hello,

Currently have 2 or 3 excel 2002 worksheets which are saved manually as
csv files - using save as for each active sheet.
OK so far, but how to do this programatically - for all the worksheets
in the xls file?
A macro perhaps?
That is question 1.
But as the results of this save as are fed into a perl script, and then
into a database. I was also wondering if any macro could be invoked
from perl?

Ta for any advice, pointers to fine manuals etc...


Tony
 
D

Dave Peterson

#1 only:

Option Explicit
Sub testme()

Dim wks As Worksheet
Dim newWks As Worksheet

For Each wks In activeworkbook.worksheets
wks.Copy 'to a new workbook
Set newWks = ActiveSheet
With newWks
Application.DisplayAlerts = False
.Parent.SaveAs Filename:="C:\TEMP\" & .Name, _
FileFormat:=xlCSV
Application.DisplayAlerts = True
.Parent.Close savechanges:=False
End With
Next wks

End Sub

This saves into a folder named C:\temp (that has to exist) and uses the
worksheet name as the file name. It also overwrites any existing file (if one
exists).

If you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top