Link to home
Start Free TrialLog in
Avatar of brothertruffle880
brothertruffle880Flag for United States of America

asked on

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

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?
Avatar of Martin Liss
Martin Liss
Flag of United States of America image

Just do File|SaveAs from Excel.
ASKER CERTIFIED SOLUTION
Avatar of ButlerTechnology
ButlerTechnology

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.