Prompt : i am working in ms excel i have multiple worksheets i want to convert each worksheet to workbook and i want to store this workbook in c drive vba folder create vba program for me
๐ VBA Code: Convert Each Worksheet into Separate Workbook
๐น Steps to Use
-
Press ALT + F11 โ VBA Editor
-
Click Insert โ Module
-
Paste the code below
-
Press F5 to run
Sub ConvertEachSheetToWorkbook()
Dim ws As Worksheet
Dim newWB As Workbook
Dim folderPath As String
Dim fileName 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
‘ Copy sheet to new workbook
ws.Copy
Set newWB = ActiveWorkbook
‘ File name = Sheet Name
fileName = folderPath & ws.Name & “.xlsx”
‘ Save workbook
newWB.SaveAs fileName:=fileName, FileFormat:=xlOpenXMLWorkbook
‘ Close new workbook
newWB.Close SaveChanges:=False
Next ws
Application.DisplayAlerts = True
Application.ScreenUpdating = True
MsgBox “All worksheets converted and saved successfully!”, vbInformation
End Sub