Copy Worksheet to another Excel file
VBA Command: Worksheet.copy
You are working in an Excel file. You want to copy one of the sheets in the current workbook to a new workbook or a already existing Excel file.
You can use this VBA code to copy a sheet from one workbook to another.Copy Sheet to New Workbook - Excel VBAVisual Basic123456789101112131415Sub Copy_Sheet_To_Workbook(iSh As Worksheet, oWb As Workbook)Dim sh As Worksheet'Intimate if any sheet with same name existsFor Each sh In oWb.WorksheetsIf VBA.LCase(sh.Name) = VBA.LCase(iSh.Name) ThenMsgBox "Sheet with Same name already exists"Exit ForEnd IfNext'Copy to Report to Input SheetiSh.Copy after:=oWb.Sheets(oWb.Sheets.Count)oWb.SaveEnd Sub
The above code will copy the worksheet to other workbook to end of the sheet.
If you would like to rename it, you can do so by using Activesheet property. Because the sheet that got copied will be in focus by default.
Activesheet.name = “CopiedSheet”
Also, You can access this sheet again with same active sheet object like this.
Set nSheet = activesheet
nSheet.range(“A1”) = 1
So, Copying a sheet from one workbook to another is not that tough. The above code is ready to use. Just copy and use it in your vba module.
Previous Post: How To Speed Up Excel VBA Macro Execution Time – Optimize?
Next Post: VBA File Open Dialog Box
Excel VBA – Copy Sheet To Another Workbook
- Block Apps in FaceBook print screen Excel Countif Record Macro Timer in Excel Task Manager VCF HTML Table Import Data Thumbnails Text to Speech TTS Candy Crush C++ Programing Machine learning AI bulk email Excel VBA vba color index vba color codes Android social media Twitter Google+ Google Adsense Tips bitcoin Calendar in Excel outlook vba mass email Data Mining Excel Macro Facebook WhatsApp python Wordpress