Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 360
Default want to save a copy as text , not save the original as text

I want to save a copy as text not the file itself.
Currently this macro works and saves a text mac file "19". If I change it to
saveCopyAs it doesn't work. It does the same thing if I change it to
another file type
so I don't think it has anything to do with the file type.
I don't want to destroy the workbook but I need to save a copy as text.
Why doesn't saveCopyAs work instead of SaveAs?

Sub saveIndesign()
'Appends date to filename so as to not write over an existing file

' saveIndesign Macro

Const fPath As String = "Mac OS X:"
Dim fName As String
Dim myFileName As String
myFileName = Left(ActiveWorkbook.Name, Len(ActiveWorkbook.Name) - 4) &
Format(Now, "yyyymmdd_hhmmss") & ".txt"


fName = fPath & myFileName
Application.DisplayAlerts = False
'do the save


ActiveWorkbook.SaveAs Filename:=fName, FileFormat:=19
Application.DisplayAlerts = True

MsgBox "File Saved to " & fName
End Sub
thanks,

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default want to save a copy as text , not save the original as text

..SaveCopyAs means what it says. It saves a copy of the existing workbook--it
keeps the same fileformat.

One way around this is to copy the worksheet to a new workbook and then save the
..txt file from there.

Sub saveIndesign()

Const fPath As String = "Mac OS X:"
Dim fName As String
Dim myFileName As String
dim Wks as worksheet

myFileName = Left(ActiveWorkbook.Name, Len(ActiveWorkbook.Name) - 4) & _
Format(Now, "yyyymmdd_hhmmss") & ".txt"

fName = fPath & myFileName

activesheet.copy 'to a new workbook
set wks = activesheet 'that sheet in the new workbook

Application.DisplayAlerts = False
wks.parent.SaveAs Filename:=fName, FileFormat:=19
Application.DisplayAlerts = True

'close that new workbook
wks.parent.close savechanges:=false

MsgBox "File Saved to " & fName
End Sub

(Untested, uncompiled)

And you may want something else besides the activesheet copied.



Janis wrote:

I want to save a copy as text not the file itself.
Currently this macro works and saves a text mac file "19". If I change it to
saveCopyAs it doesn't work. It does the same thing if I change it to
another file type
so I don't think it has anything to do with the file type.
I don't want to destroy the workbook but I need to save a copy as text.
Why doesn't saveCopyAs work instead of SaveAs?

Sub saveIndesign()
'Appends date to filename so as to not write over an existing file

' saveIndesign Macro

Const fPath As String = "Mac OS X:"
Dim fName As String
Dim myFileName As String
myFileName = Left(ActiveWorkbook.Name, Len(ActiveWorkbook.Name) - 4) &
Format(Now, "yyyymmdd_hhmmss") & ".txt"

fName = fPath & myFileName
Application.DisplayAlerts = False
'do the save

ActiveWorkbook.SaveAs Filename:=fName, FileFormat:=19
Application.DisplayAlerts = True

MsgBox "File Saved to " & fName
End Sub
thanks,


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 163
Default want to save a copy as text , not save the original as text

Hi Janis,

try this:

Sub Macro1()
ActiveWorkbook.SaveAs _
Filename:="c:\test\test.txt", FileFormat:=xlTextMac
' now save again as Excel-File
ActiveWorkbook.SaveAs _
Filename:="c:\test\test.xls", FileFormat:=xlWorkbookNormal
End Sub

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 360
Default want to save a copy as text , not save the original as text

Helmut:
Both these answers worked but this answer was very short and compact.
THANKS!

"Helmut Weber" wrote:

Hi Janis,

try this:

Sub Macro1()
ActiveWorkbook.SaveAs _
Filename:="c:\test\test.txt", FileFormat:=xlTextMac
' now save again as Excel-File
ActiveWorkbook.SaveAs _
Filename:="c:\test\test.xls", FileFormat:=xlWorkbookNormal
End Sub

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default want to save a copy as text , not save the original as text


Hi Helmut,

I have a similar need (on WindowsXP with Excel2003) except I want the text
copy to be saved automagically whenever the .xls file is saved. I tried
playing around with Workbook_BeforeSave(), but I couldn't get it to work.

Would you mind showing me how to do it correctly?

Kind regards,

Bryan Patrick
Batavia, IL, USA

Hi Janis,

try this:

Sub Macro1()
ActiveWorkbook.SaveAs _
Filename:="c:\test\test.txt", FileFormat:=xlTextMac
' now save again as Excel-File
ActiveWorkbook.SaveAs _
Filename:="c:\test\test.xls", FileFormat:=xlWorkbookNormal
End Sub

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"

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
excel save as csv - force text qualifier on every text field Newbie-Don Excel Discussion (Misc queries) 6 April 2nd 23 08:33 PM
How to save a file without overwrite or save a copy? SettingChange Setting up and Configuration of Excel 1 November 3rd 05 02:10 AM
Auto save replaced my original file and now I need the original? Hols Excel Discussion (Misc queries) 1 August 15th 05 10:34 PM
VBA to Save a file to a different format but keep original groutch Excel Programming 4 December 2nd 04 10:48 PM
Save As - Multiple Sheets fails to save as text file Ravee Srinivasan Excel Programming 2 November 10th 03 04:05 PM


All times are GMT +1. The time now is 07:26 AM.

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

About Us

"It's about Microsoft Excel"