We help IT Professionals succeed at work.

Excel Macro VBA to Append to existing file name

rsernowski
rsernowski asked
on
Hello

Looking for some Excel VBA, to pre-pend to an existing filename.  The spreadsheet comes to me with the a file name in number format  like
2015010203.xls

the file name changes daily,

so after I make my changes , i want to have excel VBA macro that prepends to the existing file name, "MAC_(then the old filename.xls)
thanks
Comment
Watch Question

Principal Analyst
Commented:
The simplest version - no test for pre-existing file of same name...

Sub PrePendToFilename()
ActiveWorkbook.SaveAs (Replace(ActiveWorkbook.FullName, ActiveWorkbook.Name, "Mac_" & ActiveWorkbook.Name))
End Sub

the simply searches for the name of the replaces the name of the existing workbook within its full path with the new name and saves the file in the same folder as the original but with the new name.

Author

Commented:
Hi Simon
Excellent , Thanks for your help