View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.misc
Norman Jones
 
Posts: n/a
Default Create text file

Hi Rob,

Try:

'=============
Public Sub Tester()
Dim WB As Workbook
Dim WB2 As Workbook
Dim SH As Worksheet
Dim rng As Range
Const newFileName As String = "B" '<<==== CHANGE

Set WB = Workbooks("A.xls") '<<==== CHANGE
Set SH = WB.Sheets("Sheet1") '<<==== CHANGE
Set rng = SH.Range("A1") '<<==== CHANGE

SH.Copy

Application.DisplayAlerts = False
With ActiveWorkbook
.SaveAs Filename:=newFileName, _
FileFormat:=xlTextWindows
.Close
End With
Application.DisplayAlerts = True

End Sub
'<<=============

If you are not familiar with macros, you may wish to visit David McRitchie's
'Getting Started With Macros And User Defined Functions' at:

http://www.mvps.org/dmcritchie/excel/getstarted.htm


---
Regards,
Norman


"Rob" wrote in message
...
Hi,

I would like to create a text file from a worksheet (named according to
the value of a cell in that worksheet), and not have the workbook from
which that sheet is attached close.

ie say the workbook is called A.xls and I create a text file called B.txt.
I want to save and close B.txt and keep A.xls open.

Can anyone help me with that?

Rob