Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 25
Default Saving a text file macro

I have to save files as text files quite often, always to the same place. I
want to be able to run a macro because the folder where these are kept is
buried, to help with security. My problem is it seems like the file has to be
named and saved as something and to somewhere before you can begin running
the macro to save it, which kind of defeats the purpose. How can I write a
macro which will allow me to save a text file, named a different name each
time, and save it to a file?
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 268
Default Saving a text file macro

Not true that you first have to save, before running the macro.

You can write a macro to save the active workbook. By using an inputbox,
you can also get the name to use

Dim Customer as String, sFName as String

Public Sub Saver()
ActiveWorkbook.SaveAs Filename:="C:\Pastel04\" & Customer & "\" &
sFName, FileFormat:=xlCSV
End Sub

will do the saving. You of course have to change the directory to whatever
suits you.
Before this, between Saver() and ActiveWorkbook, adda line to use an
inputbox to ask for a file name.

sFNAme = Inputbox("Enter the filename to be used for this file")
If you want the file changed to a .txt, I use the following, which you can
adapt:

Public Sub fRename()
lTel = 0
ChDir "C:\Pastel04\" & Customer
Workbooks("SBRecpt.csv").Close
Workbooks("SBPmt.csv").Close
vOldName = Application.GetOpenFilename(MultiSelect:=True)
If IsArray(vOldName) Then
Application.ScreenUpdating = False
For lTel = LBound(vOldName) To UBound(vOldName)
vNewName = Left(vOldName(lTel), Len(vOldName(lTel)) - 3) & "txt"
Name vOldName(lTel) As vNewName
Workbooks.Open Filename:=vNewName, UpdateLinks:=False, _
ReadOnly:=True, Format:=2
Next lTel
End If
Application.ScreenUpdating = True
End Sub


"jknapp1005" wrote:

I have to save files as text files quite often, always to the same place. I
want to be able to run a macro because the folder where these are kept is
buried, to help with security. My problem is it seems like the file has to be
named and saved as something and to somewhere before you can begin running
the macro to save it, which kind of defeats the purpose. How can I write a
macro which will allow me to save a text file, named a different name each
time, and save it to a file?

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 268
Default Saving a text file macro

Oops, of course you will have to declare the necessary variables for the
renaming procedure.

"jknapp1005" wrote:

I have to save files as text files quite often, always to the same place. I
want to be able to run a macro because the folder where these are kept is
buried, to help with security. My problem is it seems like the file has to be
named and saved as something and to somewhere before you can begin running
the macro to save it, which kind of defeats the purpose. How can I write a
macro which will allow me to save a text file, named a different name each
time, and save it to a file?

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
error when running cut & paste macro Otto Moehrbach Excel Worksheet Functions 4 August 9th 06 01:49 PM
Text File creates incorrect Date format Rob Excel Discussion (Misc queries) 2 June 23rd 06 07:53 AM
Macro Help for Saving a file [email protected] Excel Worksheet Functions 3 May 12th 06 05:16 PM
Saving sheet to text file Rob Excel Discussion (Misc queries) 4 December 9th 05 09:55 PM
saving an excel file as text without text in quotes John Excel Discussion (Misc queries) 2 December 6th 05 06:20 PM


All times are GMT +1. The time now is 02:24 AM.

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

About Us

"It's about Microsoft Excel"