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

Resetting Toolbars to Their Default

Customize Word enough, and you may at some point want to set the toolbars back to their original condition. Here's how to do ...

Discover More

Moving a Chart's Legend

Need to move a chart legend to a different place on the chart? It's easy to do using the mouse, as described in this tip.

Discover More

Displaying the Selected Cell's Address

Need to know the address of the cell that is currently selected? There is no worksheet function to return this information, ...

Discover More

Professional Development Guidance! Four world-class developers offer start-to-finish guidance for building powerful, robust, and secure applications with Excel. The authors show how to consistently make the right design decisions and make the most of Excel's powerful features. Check out Professional Excel Development today!

MORE EXCELTIPS (MENU)

Finding the Size of a Workbook

Keeping tabs on the size of a workbook can be important when using Excel. You have a couple of options that will allow you to ...

Discover More

Closing Multiple Files

When working with multiple workbooks open, you may want a way to close them all with a single command. Here's the secret.

Discover More

Sudden Increases in Workbook File Size

Workbooks can get rather large rather quickly. If you think your workbook has gotten too big too fast, here are some things ...

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 for this tip:

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. 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 nine more than 2?

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!


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.

Links and Sharing
Share