Forum Discussion
Auto creation of new sheet in a duplicate workbook when created one in original Workbook.
To achieve automatic creation of a new sheet in a duplicate workbook when a new sheet is created in the original workbook, you can use VBA (Visual Basic for Applications) in Excel. VBA allows you to automate tasks and create custom functions. Here's a step-by-step guide:
1. Open the Original Workbook:
Open the Excel workbook where you want to automatically create a new sheet in the duplicate workbook.
2.Enable Developer Tab:
If you haven't enabled the Developer tab, go to "File" -> "Options" -> "Customize Ribbon," and check the "Developer" option.
3. Access the Visual Basic for Applications (VBA) Editor:
Click on the "Developer" tab, and then click on "Visual Basic" to open the VBA Editor.
4. Insert a Module:
In the VBA Editor, right-click on any item in the "Project Explorer" on the left, choose "Insert," and then click "Module."
5. Write VBA Code:
In the module, paste the following VBA code:
Vba code is untested.
Private Sub Workbook_SheetAdded(ByVal Sh As Object)
Dim newSheet As Worksheet
Dim duplicateWorkbook As Workbook
Dim originalSheet As Worksheet
' Set the original sheet and workbook
Set originalSheet = ThisWorkbook.Sheets(Sh.Name)
Set duplicateWorkbook = Workbooks.Open("C:\Path\To\Your\DuplicateWorkbook.xlsx") ' Change the path accordingly
' Copy the original sheet to the duplicate workbook
originalSheet.Copy Before:=duplicateWorkbook.Sheets(1)
' Close the duplicate workbook without saving changes
duplicateWorkbook.Close SaveChanges:=False
End Sub- Update the path in Workbooks.Open to the path of your duplicate workbook.
6. Save and Close VBA Editor:
Save your workbook and close the VBA Editor.
Now, every time you add a new sheet in the original workbook, this VBA code will automatically create a copy of the new sheet in the specified duplicate workbook. Adjust the code and paths according to your requirements.
Remember to save your workbooks before running or testing any VBA code, as it cannot be undone once executed. The text and steps were edited with the help of AI.
My answers are voluntary and without guarantee!
Hope this will help you.
Was the answer useful? Mark as best response and Like it!
This will help all forum participants.
- Aum_KarJan 12, 2024Copper ContributorI tried the way you suggested but it didn't work in my context. Thank you for your best try.