Getting Rid of "Copy of"

by Allen Wyatt
(last updated June 23, 2018)

7

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.

Note:

If you would like to know how to use the macros described on this page (or on any other page on the ExcelTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

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

Unlocking a Worksheet with an Unknown Password

It is not unusual, in a corporate world, to be handed a worksheet whose source you don't know. If that worksheet is ...

Discover More

Selecting Multiple Cells by Mistake

Click on a cell and you expect the single cell to be selected. If you instead get a group of cells, it can be frustrating ...

Discover More

Searching for Floating Graphics

Graphics can be added to a document so that they are either inline with the text or floating over the text. You can use ...

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)

Importing Huge Data Files

Sometimes, when importing data created by other programs, you may find that there is too much for Excel to handle. Here's ...

Discover More

Creating a CSV File

Need to get your data into a format that can be easily read by other programs? Chances are good that a simple CSV file ...

Discover More

Opening Non-Excel Files

Not all data is created in Excel. Indeed, you may have data in files created by many other types of programs. You might ...

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 6Mpixels. 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 six more than 9?

2018-03-21 11:11:18

Paul

What exactly is the "PERSONAL FILE"?

Do I only create one excel file with the code and then its Universal?

What does the "Workbook_Open event macro" refer to? the macro in the post?

So I...
open brand new excel spreadsheet,
add new class-module, copy and paste code
add new module, copy and paste code
in ThisWorkBook under VBAProject/Microsoft Excel Objects, add Set XL_Events.XL_Event = Application

?


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.