
Tips.Net > ExcelTips Home > Files > Getting Rid of "Copy of"
Summary: When you open a read-only workbook, and then display the Save As dialog box, the words “Copy of” are added as a prefix to the suggested file name. This tip discusses how you can get rid of these added words so you can save quicker and more efficiently. (This tip works with Microsoft Excel 97, Excel 2000, Excel 2002, and Excel 2003.)
Anna Lea has a read-only workbook that she uses as a template for a daily report that she creates. The file name is quite long, and ends in 20507xx. When she double-clicks on the workbook, it opens and shows that it is read-only. She makes her changes, and then chooses File | Save As. Since Excel recognizes that the file is read-only, it suggests a new file name that consists of the old one with the words "Copy of" as a prefix. Anna wants to get rid of the "Copy of" so that all she has to do is change the "xx" portion of the file name to create the day's report.
The "Copy of" verbiage is added by Excel automatically. If you are using Save As, there is no way to change this without using a macro to control the saving process. The following macro, saved as part of the ThisWorkbook object, shows how this can be done.
Private Sub Workbook_BeforeSave(ByVal SaveAsUI _
As Boolean, Cancel As Boolean)
Dim sTemp As String
If SaveAsUI Then
sTemp = ThisWorkbook.Name
If Right(sTemp, 6) = "xx.xls" Then
sTemp = Left(sTemp, Len(sTemp) - 6)
sTemp = sTemp & Format(Now, "dd") & ".xls"
sTemp = ThisWorkbook.Path & "/" & sTemp
ThisWorkbook.SaveAs Filename:=sTemp, _
FileFormat:=xlNormal
Cancel = True
End If
End If
End Sub
The macro first checks to see if the Save As dialog box is about to be displayed. If it is, then the workbook's name is assigned to the sTemp variable. This name is checked to see if the last six characters are "xx.xls". If they are, then the workbook is assumed to be the one where the name needs to be changed.
First the "xx.xls" characters are stripped from the end of the workbook name. Then today's date (two digits, for the day of the month) is appended to the file name, followed by the ".xls" suffix. Finally, the workbook is saved using this newly constructed filename. The Cancel flag is set to True so that the Save As dialog box never displays.
Note that the name is never checked for the verbiage "Copy of". The reason for this is simple: The wording is not added to the start of the file name until the actual Save As dialog box is displayed. Before that point (when this event handler is being executed) the workbook name remains unchanged.
Tip #3064 applies to Microsoft Excel versions: 97 2000 2002 2003
Got the Time? If you work with either times or dates in Excel, you really need ExcelTips: Times and Dates. Everything you need to know about slicing, dicing, and generally working with times and dates.
Add power to your purpose with Excel. A comprehensive 500+ page e-book explains everything you need to know about macros. (more information...)
Ask an Excel Question
Make a Comment
ExcelTips FAQ
ExcelTips Premium
Beauty Tips
Car Tips
Cleaning Tips
College Tips
Cooking Tips
Excel2007 Tips
ExcelTips
Family Tips
Gardening Tips
Health Tips
Home Tips
Money Tips
Pet Tips
Word2007 Tips
WordTips
Advertise on the
ExcelTips Site