sspatriots
Well-known Member
- Joined
- Nov 22, 2011
- Messages
- 585
- Office Version
- 365
- Platform
- Windows
I found the following statement on a Microsoft learning website:
"If you don't specify either Before or After, Microsoft Excel creates a new workbook that contains the copied Worksheet object. The newly created workbook holds the Application.ActiveWorkbook property and contains a single worksheet. The single worksheet retains the Name and CodeName properties of the source worksheet. If the copied worksheet held a worksheet code sheet in a VBA project, that is also carried into the new workbook."
I have a macro that goes out and gets a worksheet from another workbook and copies it into my workbook. However, the worksheet code does not come with it. Am I doing something wrong or misinterpreting the statement?
Thanks, SS
"If you don't specify either Before or After, Microsoft Excel creates a new workbook that contains the copied Worksheet object. The newly created workbook holds the Application.ActiveWorkbook property and contains a single worksheet. The single worksheet retains the Name and CodeName properties of the source worksheet. If the copied worksheet held a worksheet code sheet in a VBA project, that is also carried into the new workbook."
I have a macro that goes out and gets a worksheet from another workbook and copies it into my workbook. However, the worksheet code does not come with it. Am I doing something wrong or misinterpreting the statement?
Thanks, SS
VBA Code:
Sub CopyPRODSCHEDFromClosedWB()
Application.ScreenUpdating = False
Set closedBook = Workbooks.Open(Filename:="H:\DEM Shop Files\MRL Production Schedule\DEM Production Schedule.xlsm") 'Selected File full path
closedBook.Sheets("COMM - In Production").Copy Before:=ThisWorkbook.Worksheets("2023")
closedBook.Sheets("COMM - Completed").Copy Before:=ThisWorkbook.Worksheets("2023")
closedBook.Sheets("MRL - In Production").Copy Before:=ThisWorkbook.Worksheets("2023")
closedBook.Sheets("MRL - Completed").Copy Before:=ThisWorkbook.Worksheets("2023")
closedBook.Close SaveChanges:=False
Application.ScreenUpdating = True
End Sub