Solved

Excel 2010 VBA - How to Copy the current workbook (with VBA modules)

Posted on 2013-11-18
3
650 Views
Last Modified: 2013-11-18
I have a workbook BUDGET.XLSM and it has code that I need and want.  I want to
1) make a copy of this workbook
2) name the new workbook "NEW BUDGET.XLSM"  
3) in the new copy. I want to delete an unnecessary worksheet named "OLD".

The code that will be executing this will be resident in budget.xlsm.

Can someone help me with this code?
0
Comment
Question by:brothertruffle880
3 Comments
 
LVL 45

Expert Comment

by:Martin Liss
ID: 39657953
Just do File|SaveAs from Excel.
0
 
LVL 6

Accepted Solution

by:
ButlerTechnology earned 500 total points
ID: 39658046
The following code will do what you are looking for...
Public Sub DuplicateWorkbook()

ActiveWorkbook.SaveCopyAs "New Budget.xlsm"
Workbooks.Open "New Budget.xlsm"
ActiveWorkbook.Sheets("OLD").Delete
End Sub

Open in new window


Tom
0
 
LVL 15

Expert Comment

by:David L. Hansen
ID: 39658049
Just in case you were thinking "copy WORKSHEET to a different WORKBOOK" here's the code:
Sub CopyWorksheets()

Dim wbGenerated as Workbook, wbTemplate as Workbook
Dim ws as Worksheet

Set wbGenerated = Workbooks("Generated.xlsx")
Set wbTemplate = Workbooks("TemplateASA.xlsx") 'If this line fails, remove it and uncomment the following line
' Set wbTemplate = Workbooks.Open("TemplateASA.xlsx", ,True) ' Opens as read only
For Each sh In wbTemplate.Worksheets
   sh.Copy After:=wbGenerated.Sheets(wbGenerated.Sheets.Count)
Next sh
'wbTemplate.Close(False) 'Only required if you opened wbTemplate above

End sub

Open in new window

Taken from here.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
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…
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.

762 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now