Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.misc
|
|||
|
|||
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
Posted to microsoft.public.excel.misc
|
|||
|
|||
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
Posted to microsoft.public.excel.misc
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
error when running cut & paste macro | Excel Worksheet Functions | |||
Text File creates incorrect Date format | Excel Discussion (Misc queries) | |||
Macro Help for Saving a file | Excel Worksheet Functions | |||
Saving sheet to text file | Excel Discussion (Misc queries) | |||
saving an excel file as text without text in quotes | Excel Discussion (Misc queries) |