How to Use Excel VBA to Save a Sheet as a New Workbook without Opening It (6 Examples)

Example 1 – Renaming a Sheet and Saving It as a New Workbook

  • Open your workbook in Excel.
  • Press Alt + F11 to open the Visual Basic for Applications (VBA) editor.

  • Click on Insert and select Module to create a new module.

excel vba save sheet as new workbook without opening

  • In the module, paste the following code:
Sub RenameAndSaveSheet()
Application.EnableEvents = False
Application.DisplayAlerts = False
ActiveWorkbook.Sheets(2).Copy
ActiveWorkbook.Sheets(1).Name = "SalesInfo"
ActiveWorkbook.SaveAs "C:\Users\DELL\Desktop\Nahian\blog 54\Rename_Sheet", FileFormat:=51
ActiveWorkbook.Close False
Application.EnableEvents = True
Application.DisplayAlerts = True
End Sub

Code Explanation

  • We named our Sub Procedure as RenameAndSaveSheet.
  • We set EnableEvents and DisplayAlerts to False.
  • We copied the second sheet and renamed it as SalesInfo.
  • We used the SaveAs method to save the workbook.
  • The file will be saved at the specified location.
  • Run the code by clicking the Run button in the VBA Editor.

excel vba save sheet as new workbook without opening

  • Check the specified file location to find the newly created workbook named Rename_Sheet.

  • Open it and the 2nd sheet of the previous workbook becomes a new workbook itself. The name of the 2nd sheet changes to SalesInfo.

excel vba save sheet as new workbook without opening


Example 2 – Saving a Single Sheet as a New Workbook

  • Follow the same steps to open the VBA Module.
  • Paste the following code in the module:
Sub SaveSheetInNewWorkbook()
    Dim File_Name As String
    Dim File_Path As String
    File_Path = "C:\Users\DELL\Desktop\Nahian\blog 54\Save"
    File_Name = " Workbook Without Opening" & ".xlsx"
    Application.DisplayAlerts = False
    Application.ScreenUpdating = False
    ThisWorkbook.Sheets("dataset").Copy
    If Dir(File_Path & "" & File_Name) <> "" Then
    MsgBox "File " & File_Path & "" & File_Name & " already exists"
    Else
    ActiveWorkbook.SaveAs Filename:=File_Path & "" & File_Name
    Application.ActiveWorkbook.Close False
    End If
    Application.DisplayAlerts = True
    Application.ScreenUpdating = True
End Sub

excel vba save sheet as new workbook without opening

Code Explanation

  • We named our Sub Procedure as SaveSheetInNewWorkbook.
  • We declare variables File_Name and File_Path.
  • We set the file location and file name.
  • We copy the dataset sheet from the current workbook.
  • If the file already exists, a message box will appear.
  • Otherwise, the new workbook will be saved.
  • Run the code using the Run button in the VBA Editor.

  • Check the specified file location for the newly created workbook named Workbook Without Opening.

excel vba save sheet as new workbook without opening

  • Open it and the dataset sheet of the previous workbook becomes a new workbook itself.

Read More: How to Save a Worksheet as a New File Using Excel VBA


Example 3 – Saving Each Sheet as New Workbook

  • Open your workbook in Excel.
  • Press Alt + F11 to open the Visual Basic for Applications (VBA) editor.
  • Click on Insert and select Module to create a new module.
  • In the module, paste the following code:
Sub SaveMultipleSheets()
Dim location As String
location = "C:\Users\DELL\Desktop\Nahian\blog 54\Multiple Sheets\sheet_"
Application.ScreenUpdating = False
Application.DisplayAlerts = False
For Each Sheet In ThisWorkbook.Sheets
    Sheet.Copy
    Application.ActiveWorkbook.SaveAs location & Sheet.Name & ".xlsx"
    Application.ActiveWorkbook.Close False
Next
Application.ScreenUpdating = True
End Sub

excel vba save sheet as new workbook without opening

Code Explanation

  • We named our Sub Procedure as SaveMultipleSheets.
  • We declare the variable location as a String to set the file location.
  • We use a For Each loop to copy all the sheets of the current workbook.
  • Each sheet is saved as a new workbook with a filename based on its original name.
  • Run the code by clicking the Run button in the VBA Editor.

  • Check the specified file location to find individual workbooks for each sheet.

excel vba save sheet as new workbook without opening

  • Open the 1st workbook to see what actually happens.

.

You can save every sheet as a new workbook without opening it by using Excel VBA.


Example 4 – Saving Each Sheet as New Workbook Based on a Word or Text

  • Follow the same steps to open the VBA Module.
  • Paste the following code in the module:
Sub SaveSheetBasedOnWord()
Dim Target_Path As String
Dim Target_Text As String
Target_Text = "3"
Target_Path = "C:\Users\DELL\Desktop\Nahian\blog 54\Save Sheet Based on Word"
Application.ScreenUpdating = False
Application.DisplayAlerts = False
For Each Sheet In ThisWorkbook.Sheets
If InStr(1, Sheet.Name, Target_Text, vbBinaryCompare) <> 0 Then
Sheet.Copy
Application.ActiveWorkbook.SaveAs _
Filename:=Target_Path & "\" & Sheet.Name & ".xlsx"
Application.ActiveWorkbook.Close False
End If
Next
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub

excel vba save sheet as new workbook without opening

Code Explanation

  • We named our Sub Procedure as SaveSheetBasedOnWord.
  • We declare the variables Target_Path and Target_Text as Strings.
  • Target_Text represents the word or text we want to match in the sheet names (e.g., 3).
  • The code copies sheets containing the specified text and saves them as new workbooks.
  • Run the code using the Run button in the VBA Editor.

  • Check the specified file location for the newly created workbook(s) based on the word or text.

excel vba save sheet as new workbook without opening

  • Open it and the dataset3 sheet of the previous workbook becomes a new workbook itself. Open it to see the content of this workbook.


Example 5 – Saving Multiple Sheets into a New Workbook

  • Open your workbook in Excel.
  • Press Alt + F11 to open the Visual Basic for Applications (VBA) editor.
  • Click on Insert and select Module to create a new module.
  • In the module, paste the following code:
Option Explicit

Sub SaveSelectedSheets()
Dim Workbook_Source As Workbook, Target_Workbook As Workbook
Dim Sheet_List As String
Dim Sheet_Array As Variant
Dim Array_Index As Long
On Error GoTo errHandle
Sheet_List = "dataset1:dataset2"
Sheet_Array = Split(Sheet_List, ":")
If UBound(Sheet_Array) = -1 Then Exit Sub
Set Workbook_Source = ThisWorkbook
Set Target_Workbook = Workbooks.Add
Application.DisplayAlerts = False
Application.ScreenUpdating = False
For Array_Index = LBound(Sheet_Array) To UBound(Sheet_Array)
ThisWorkbook.Worksheets(Sheet_Array(Array_Index)).Copy Target_Workbook.Worksheets(Target_Workbook.Worksheets.Count)
Next Array_Index
ChDir "C:\Users\DELL\Desktop\Nahian\blog 54"
ActiveWorkbook.SaveAs Filename:="C:\Users\DELL\Desktop\Nahian\blog 54\Save Specified Sheets with VBA.xlsx", CreateBackup:=False
ActiveWorkbook.Close False
Application.DisplayAlerts = True
Application.ScreenUpdating = True
CleanObjects:
Set Target_Workbook = Nothing
Set Workbook_Source = Nothing
Exit Sub
errHandle:
MsgBox "Error: " & Err.Description, vbExclamation
GoTo CleanObjects
End Sub

excel vba save sheet as new workbook without opening

Code Explanation

  • We named our Sub Procedure as SaveSelectedSheets.
  • We define the sheet names we want to save as a new workbook (in this case, dataset1 and dataset2).
  • The code creates a new workbook (Target_Workbook) and copies the specified sheets from the current workbook (Workbook_Source) into it.
  • The new workbook is saved with the specified filename and location.
  • Run the code by clicking the Run button in the VBA Editor.

  • Check the specified file location to find the newly created workbook named Save Specified Sheets with VBA.

excel vba save sheet as new workbook without opening

  • Open it and the dataset1 and dataset2 sheets of the previous workbook are in a new workbook itself.


Example 6 – Using VBA to Save Selected Sheet as a New Workbook

  • Open your workbook in Excel.
  • Press Alt + F11 to open the Visual Basic for Applications (VBA) editor.
  • Click on Insert and select Module to create a new module.
  • In the module, paste the following code:
Sub SaveSheetByArrayVariable()
    Sheets(Array("dataset1", "dataset2", "dataset3")).Select
    Sheets("dataset1").Activate
    Sheets(Array("dataset1", "dataset2", "dataset3")).Copy
    ChDir "C:\Users\DELL\Desktop\Nahian\blog 54"
    ActiveWorkbook.SaveAs Filename:="C:\Users\DELL\Desktop\Nahian\blog 54\Save Sheets by VBA_2.xlsx", _
    CreateBackup:=False
    ActiveWorkbook.Close False
End Sub

excel vba save sheet as new workbook without opening

Code Explanation

  • We use the Selection Property to select the sheets dataset1, dataset2, and dataset3 as an Array variable.
  • We activate the dataset1 sheet (you can activate any of the three).
  • The ChDir statement changes the default directory to the specified location where the new workbook will be saved.
  • We use the VBA SaveAs method to save the workbook.
  • Run the code by clicking the Run button in the VBA Editor.

excel vba save sheet as new workbook without opening

  • Check the specified file location to find the newly created workbook named Save Sheets by VBA_2.

  • Open it, and the dataset1, dataset2, and dataset3 sheets from the previous workbook are in a new workbook.

excel vba save sheet as new workbook without opening


Practice Section

You are provided with the dataset of this file so that you can practice these methods.


Download Practice Workbook

You can download the practice workbook from here:

Get FREE Advanced Excel Exercises with Solutions!
Meraz Al Nahian
Meraz Al Nahian

Md. Meraz Al Nahian has worked with the ExcelDemy project for over 1.5 years. He wrote 140+ articles for ExcelDemy. He also solved a lot of user problems and worked on dashboards. He is interested in data analysis, advanced Excel, statistics, and dashboards. He also likes to explore various Excel and VBA applications. He completed his graduation in Electrical & Electronic Engineering from Bangladesh University of Engineering & Technology (BUET). He enjoys exploring Excel-related features to gain efficiency... Read Full Bio

2 Comments
  1. Hi,

    Could you please write a code that how to execute option # 6 with a Command Button.

    Thanks

    • Reply Lutfor Rahman Shimanto
      Lutfor Rahman Shimanto Dec 14, 2023 at 12:41 PM

      Hello ZAPPER

      Thanks for reading ExcelDemy Blogs. You wanted a button to click and copy some sheets in a folder.

      I am delighted to inform you that I have enhanced the sub-procedure so you will like it. The sub-procedure will create a folder dynamically, and the path will be the workbook path. Besides, it will handle errors as well. I have inserted a print icon and assigned the sub-procedure as follows.

      OUTPUT OVERVIEW:

      Enhanced Excel VBA Sub-procedure:

      
      Sub AdvancedSaveSheetByArrayVariable()
      
          Dim currentPath As String
          currentPath = ThisWorkbook.Path
          
          Dim folderPath As String
          folderPath = currentPath & "\" & "SavedSheetsFolder"
          
          On Error GoTo ErrHandle
          
          MkDir folderPath
          
          Sheets(Array("dataset1", "dataset2", "dataset3")).Select
          Sheets("dataset1").Activate
          Sheets(Array("dataset1", "dataset2", "dataset3")).Copy
      
          With ActiveWorkbook
              .SaveAs Filename:=folderPath & "\" & "SaveSheetsByVBA_2.xlsx", CreateBackup:=False
              .Close False
          End With
          
          Exit Sub
      
      ErrHandle:
      
          MsgBox "Folder and File Exist. Remove the previous folder and file.", vbCritical
      
      End Sub
      

      I am attaching the solution workbook for better understanding. Good luck.

      DOWNLOAD WORKBOOK

      Regards
      Lutfor Rahman Shimanto
      ExcelDemy

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo