Getting Rid of "Copy of"

by Allen Wyatt
(last updated June 1, 2013)

6

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 uses 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
    Dim sCheck As String
    sCheck = "xx.xls"

    If SaveAsUI Then
        sTemp = ThisWorkbook.Name
        If Right(sTemp, Len(sCheck)) = sCheck Then
            sTemp = Left(sTemp, Len(sTemp) - Len(sCheck))
            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" (from the sCheck variable). If they are, then the workbook is assumed to be the one where the name needs to be changed.

First the "xx.xls" characters (or whatever you've assigned to sCheck) 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.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (3064) applies to Microsoft Excel 97, 2000, 2002, and 2003.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He  is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Unhiding Multiple Worksheets

You can hide a bunch of worksheets at the same time, but Excel makes it impossible to unhide a bunch at once. You can, ...

Discover More

Adding a Hidden Tool in Word

Word no longer includes a Hidden tool on the ribbon as it used to in earlier versions that used toolbars. You can still add ...

Discover More

Should I Leave My Computer On All the Time?

Do you turn your computer on and off all the time? Do you really know if this is good for your computer or not?

Discover More

Save Time and Supercharge Excel! Automate virtually any routine task and save yourself hours, days, maybe even weeks. Then, learn how to make Excel do things you thought were simply impossible! Mastering advanced Excel macros has never been easier. Check out Excel 2010 VBA and Macros today!

More ExcelTips (menu)

Saving Information in a Text File

The VBA programming language provide with Excel allows you to create and modify text files quite easily. Here's how to open a ...

Discover More

Saving Worksheets in Lotus 1-2-3 Format

You can export an Excel worksheet in a variety of formats. One of those formats is Lotus 1-2-3, which is available as an ...

Discover More

Comma-Delimited Differences for PC and Mac

When you choose to save worksheet data in CSV format, Excel gives you three choices for file formats. Those choices are ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 8Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 5 + 0?

2016-05-31 23:49:32

Byron Whitman

How do I delete all these copies? The make another copy every time!


2016-02-13 06:17:00

Michael (Micky) Avidan

Sorry for my bad English but I'm sure you will understand the following:

The process is, slightly, complex, and requires some skill in using the VBA Editor (VBE).

*** ALL that follows goes into the PERSONAL file.

1. Add a new ClassModule and call it: MyEventsClass

2. Type into it the code below:
Public WithEvents XL_Event As Application
Private Sub XL_Event_WorkbookBeforeSave (ByVal Wb As Workbook, ByVal SaveAsUI As Boolean, Cancel As Boolean)
If instr (Wb .Name, "Copy of") Then
Application.EnableEvents = 0
Cancel = True
Wb.SaveAs Trim (Application.Substitute (Wb.FullName, "Copy of", ""))
Application.EnableEvents = 1
End If
End Sub

3. In a regular Module (existing or new) type the command:
Public XL_Events As New MyEventsClass

4. Into ThisWorkbook module add the Workbook_Open event macro and type into it the command:
Set XL_Events.XL_Event = Application

5. Save the PERSONAL file > close and restart "Excel".

6. Try to save an open workbook which has the "Copy of" Prefix in its name.
--------------------------
Michael (Micky) Avidan
“Microsoft® Answers" - Wiki author & Forums Moderator
“Microsoft®” MVP – Excel (2009-2016)
ISRAEL


2016-02-12 09:46:24

Joanne Mueller

Let me add my annoyance to this stupid prefix that is added to every Excel worksheet I receive and want to save. I am not a programmer and have no idea what or how to find "ThisWorkbook" and add the macro as suggested above. Microsoft just needs to eliminate this stupid harassment.


2015-08-28 10:04:08

Richard Reynolds

Once can only ask ... Why? WHY?? I exchange Excel files with lots of people via E-mail. Every one is aggravated by this "Copy of..." behavior of Excel.

Why not "Copy of ..." a Word or PowerPoint document? (Oops, did I give Microsoft an idea! Hope NOT!)


2014-12-01 17:27:45

Jon Faulkner

This is a lot of trouble. Is there a universal switch tog et rid of this annoying behavior? I get this every time I save a document from e-mail. I think this is another reason to move our firm (only 800 users of Excel) away from Microsoft to Google Docs!

Microsoft must absolutely HATE its customers to stop innovating and instead be annoying!


2013-12-09 16:39:16

Brian Fletcher

Hello Allen,
Thanks for the useful code. I wonder if there is a way to disable this in all workbooks? I would be quite content to eliminate this behavior from Excel in its entirety.
Thanks again!


This Site

Got a version of Excel that uses the menu interface (Excel 97, Excel 2000, Excel 2002, or Excel 2003)? This site is for you! If you use a later version of Excel, visit our ExcelTips site focusing on the ribbon interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.