ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Saving a text file macro (https://www.excelbanter.com/excel-discussion-misc-queries/108560-saving-text-file-macro.html)

jknapp1005

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?

kassie

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?


kassie

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?



All times are GMT +1. The time now is 08:19 PM.

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