jeffcoleky
Active Member
- Joined
- May 24, 2011
- Messages
- 274
I have two scenarios where I need to rename an existing filename to append that file's last modified date/time to the end of the file. The most recently saved file needs to retain the original filename without a date.
Using this information above, if within a macro I try to save FileName.csv and it already exists, it should rename the existing FileName.csv to "FileName 03022017 0500.csv" and then save current file as FileName.csv.
I suppose you could "copy" the existing FileName.csv to "FileName date time.csv" instead of saving as, to avoid sharing issues?
Here are two of my macros I need help modifying that will rename the existing FileName.csv before saving:
<need to="" save="" existing="" filename.csv="" instead="" of="" killing="" it.
<need to="" save="" existing="" filename.csv="" instead="" of="" killing="" it.
Any ideas?</need>
Directory: C:\temp
Existing Filename: FileName.csv
File's last Mod Date/Time: 3/2/2017 5:00a
Existing Filename: FileName.csv
File's last Mod Date/Time: 3/2/2017 5:00a
Using this information above, if within a macro I try to save FileName.csv and it already exists, it should rename the existing FileName.csv to "FileName 03022017 0500.csv" and then save current file as FileName.csv.
I suppose you could "copy" the existing FileName.csv to "FileName date time.csv" instead of saving as, to avoid sharing issues?
Here are two of my macros I need help modifying that will rename the existing FileName.csv before saving:
<need to="" save="" existing="" filename.csv="" instead="" of="" killing="" it.
<need to="" save="" existing="" filename.csv="" instead="" of="" killing="" it.
Code:
Sub Save_Existing_CSV_WITH_MODDATE() 'Rename Filename.csv before doing a SaveAs Filename.csv
If exist Then Kill "C:\temp\FileName.csv" 'Don't want it killed...
Range("A1").FormulaR1C1 = "text"
Set myrng = ActiveWindow.RangeSelection
Set newbook = Workbooks.Add
With newbook
.Title = "FileName"
.SaveAs FileName:="C:\temp\FileName.csv", FileFormat:=xlCSV
End With
Workbooks("FileName.csv").Save
Workbooks("FileName.csv").Close
End Sub
Code:
Sub Save_Existing_CSV_WITH_MODDATE() 'Rename currently open Filename.csv before doing a save on Filename.csv
Workbooks.Open ("C:\temp\FileName.csv") 'Need to save existing filename.csv before modifying original.
Windows("FileName").Activate
Range("A1").FormulaR1C1 = "text"
Workbooks("FileName.csv").Save
Workbooks("FileName.csv").Close
End Sub</need>
Any ideas?</need>
Last edited: