Saving worksheets using a Macro

  • Thread starter Thread starter lqfong
  • Start date Start date
L

lqfong

Hi,

I have multiple worksheets, and I need to save them in text ta
delimited format.

How can I do this using macros? For example I have 5 worksheets, th
macro would save the worksheets as sheet1.txt, sheet2.txt, sheet3.tx
etc...

Thanks
 
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 & ".txt", _
FileFormat:=xlText
Application.DisplayAlerts = True
.Parent.Close savechanges:=False
End With
Next wks
End Sub

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