VBA Code to Copy Active Worksheet into a New Workbook in Excel

VBA code that you can use to copy the active worksheet into a new workbook in Excel.

VBA Code:

Sub CopyActiveWorksheetToNewWorkbook()
    Dim newWorkbook As Workbook
    Dim activeWorksheet As Worksheet
    
    ' Set the active worksheet
    Set activeWorksheet = ActiveSheet
    
    ' Create a new workbook
    Set newWorkbook = Workbooks.Add
    
    ' Copy the active worksheet to the new workbook
    activeWorksheet.Copy Before:=newWorkbook.Sheets(1)
    
    ' Save the new workbook with a desired name and location
    newWorkbook.SaveAs "C:\Path\To\Save\NewWorkbook.xlsx" ' Change the path and filename as desired
    
    ' Close the new workbook
    newWorkbook.Close SaveChanges:=False
    
    ' Inform the user that the worksheet has been copied to a new workbook
    MsgBox "The active worksheet has been copied to a new workbook!"
End Sub


Check All VBA Codes

Join Our Telegram Group techguruplus telegram group Join Our WhatsApp Group techguruplus whatsapp group
Nazim Khan - Author Image

Nazim Khan (Author)

Nazim Khan is an expert in Microsoft Excel. He teaches people how to use it better. He has been doing this for more than ten years. He has a website and a YouTube channel called "Business Excel." He shares useful tips from his own experiences to help others improve their Excel skills and careers.

Leave a Comment