
Via VBA (I have 8 pivot tables and I will create any of these 8 by VBA). I am changing my code now and will insert a sheet and its corresponding pivot table Mybook.Sheets("mySheet").Copy Before:=Workbooks("Book1.xlsx").I used 2 Active X Command buttons to do run some VBA code and I realized that the code is saved with that specific sheet, and the specific sheet has a pivot table. In the same way, you can copy and move a sheet from a closed workbook. Copy Sheet from Another Workbook without Opening it We have turned off the screen updating so that code can perform the task at the backend. In this code, you have the myBook variable and then a workbook assigned to it. Workbooks("Book1.xlsx").Sheets("Sheet2").Copy Before:=mybook.Sheets(1) ("C:\Users\Dell\Desktop\samplefile.xlsx") There’s a way that you can copy a sheet to a workbook that is closed and you don’t need to open it.

Sheets("Sheet1").Move Before:=Workbooks("Book1.xlsx").Sheets(1) Copy a Sheet to a Closed Workbook The above code copies the Sheet1 from the active workbook and adds to the before the first sheet of the Book1.xlsx that is already open.Īnd if you want to move it. Sheets("Sheet1").Copy Before:=Workbooks("Book1.xlsx").Sheets(1) If you want to copy a sheet to another workbook that is already open then you can mention the workbook name in the after or before the argument.

The above code creates an array of the sheets and then copy all of them to a new workbook. If you want to add multiple sheets to the new workbook in one go then use code like the following. Sheets("Sheet5").Move Copy Multiple Sheets to the New Workbook Sheets("Sheet5").CopyĪnd to move a sheet to a new workbook. When you use the copy method without defining any sheet in the current workbook, VBA opens a new workbook and copy that sheet to that workbook. This code will move the “Sheet5” before the “Sheet2” as you can see in the above snapshot.
