ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Export Areas (https://www.excelbanter.com/excel-discussion-misc-queries/1135-export-areas.html)

Michael MacLachlan

Export Areas
 
Is it possible to export certain areas from Sheets in a workbook
automatically to single .CSV Files with the name of the sheet ?
E.G.: The Range A:5 - Z:89 for the Sheets named Argentina, Austria,...
should produce .CSV Files named : Argentina.csv, Austria.csv ......


Vikrant Vaidya

Start recording a macro and do it manually once. then next time just run that
macro. You will find record macros in ToolsMacro

"Michael MacLachlan" wrote:

Is it possible to export certain areas from Sheets in a workbook
automatically to single .CSV Files with the name of the sheet ?
E.G.: The Range A:5 - Z:89 for the Sheets named Argentina, Austria,...
should produce .CSV Files named : Argentina.csv, Austria.csv ......


Dave Peterson

How do you know which worksheets to copy?

If you can copy all the worksheets in the workbook, then you could use code
like:

Option Explicit
Sub testme()

Dim wks As Worksheet
Dim newWks As Worksheet

For Each wks In ActiveWorkbook.Worksheets
'or use this for your selected sheets
'For Each wks In ActiveWindow.SelectedSheets
Set newWks = Workbooks.Add(1).Worksheets(1)
wks.Range("a5:z89").Copy _
Destination:=newWks.Range("a1")
With newWks
Application.DisplayAlerts = False
.Parent.SaveAs Filename:="C:\WINDOWS\TEMP\" & wks.Name, _
FileFormat:=xlCSV
Application.DisplayAlerts = True
.Parent.Close savechanges:=False
End With
Next wks

End Sub

If you have to ignore some of the worksheets, maybe you could group the sheets
(click on the first worksheet tab and ctrl-click on subsequent), then uncomment
the activewindow line and comment the activeworkbook line.

For Each wks In ActiveWorkbook.Worksheets
'or use this for your selected sheets
'For Each wks In ActiveWindow.SelectedSheets



Michael MacLachlan wrote:

Is it possible to export certain areas from Sheets in a workbook
automatically to single .CSV Files with the name of the sheet ?
E.G.: The Range A:5 - Z:89 for the Sheets named Argentina, Austria,...
should produce .CSV Files named : Argentina.csv, Austria.csv ......


--

Dave Peterson

Dave Peterson

And don't forget to adjust the path to an existing folder.

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

Michael MacLachlan wrote:

Is it possible to export certain areas from Sheets in a workbook
automatically to single .CSV Files with the name of the sheet ?
E.G.: The Range A:5 - Z:89 for the Sheets named Argentina, Austria,...
should produce .CSV Files named : Argentina.csv, Austria.csv ......


--

Dave Peterson


All times are GMT +1. The time now is 06:16 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com