Excel Macro to copy and rename when workbook is saved

Posted on 2011-09-14
Last Modified: 2012-05-12

I need a macro that will copy the opened workbook to a destination saved as the same filename & datetime. I need the macro to generate as soon as the workbook is saved. Any ideas?

Question by:asmyatt
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
LVL 29

Expert Comment

by:Randy Downs
ID: 36536614
Maybe this will help

... simply copying your master/template sheet (it looks like you are copying everything). This is equivilent to EDIT > "Move or Copy Sheet" > checking the "Create a copy" box

Sub CopySheet()
    Dim MySheetName As String
    MySheetName = "TestSheet"
    Sheets("MasterSheet").Copy After:=Sheets("MasterSheet")
    ActiveSheet.Name = MySheetName
End Sub

Author Comment

ID: 36536796
I need the macro to save the entire excel file to another excel file.
LVL 29

Accepted Solution

Randy Downs earned 500 total points
ID: 36536980
Try this. You may need to close your file before copying though.

Dim SrceFile
Dim DestFile

SrceFile = "g:\jerry\"
DestFile = "c:\data\zippedfiles\"
FileCopy SrceFile, DestFile

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question