I am working in MS Excel i have multiple worksheets and I want to convert each worksheet to a Workbook I want to save these workbooks in the C drive VBA Folder please create a VBA Program for me
Below is a safe and commonly used VBA program that will convert each worksheet into a separate workbook and save them in C:\VBA Folder.
The code will automatically create the folder if it does not already exist.
Sub ConvertEachSheetToWorkbook()
Dim ws As Worksheet
Dim newWB As Workbook
Dim folderPath As String
‘ Folder path
folderPath = “C:\VBA Folder\”
‘ Create folder if it does not exist
If Dir(folderPath, vbDirectory) = “” Then
MkDir folderPath
End If
Application.ScreenUpdating = False
Application.DisplayAlerts = False
‘ Loop through each worksheet
For Each ws In ThisWorkbook.Worksheets
‘ Add new workbook
Set newWB = Workbooks.Add
‘ Copy sheet to new workbook
ws.Copy Before:=newWB.Sheets(1)
‘ Delete extra default sheets
Do While newWB.Sheets.Count > 1
newWB.Sheets(2).Delete
Loop
‘ Save the workbook
newWB.SaveAs folderPath & ws.Name & “.xlsx”, FileFormat:=xlOpenXMLWorkbook
‘ Close new workbook
newWB.Close SaveChanges:=False
Next ws
Application.DisplayAlerts = True
Application.ScreenUpdating = True
MsgBox “All worksheets converted successfully!”, vbInformation
End Sub