Hi,
Can anyone please help me to create a VBA for a Workbook with multiple Worksheets which is stored in a particular folder ; extract each worksheet to a New Workbook with Sheet Name and put in a folder predefined by user as per below:
VBA Code I've tried creating is as follows:
Can anyone please help me to create a VBA for a Workbook with multiple Worksheets which is stored in a particular folder ; extract each worksheet to a New Workbook with Sheet Name and put in a folder predefined by user as per below:
VBA Code I've tried creating is as follows:
VBA Code:
Sub copysheet()
Application.DisplayAlerts = False
'Retrieve Target Folder Path From User
Set FldrPicker = Application.FileDialog(msoFileDialogFolderPicker)
With FldrPicker
.Title = "Select A Target Folder"
.AllowMultiSelect = False
If .Show <> -1 Then GoTo NextCode
myPath = .SelectedItems(1) & "\"
End With
'Target File Extension (must include wildcard "*")
myExtension = "*.xlsx*"
'Target Path with Ending Extention
myFile = Dir(myPath & myExtension)
'Loop through each Excel file in folder
Do While myFile <> ""
Set wb = Workbooks.Open(Filename:=myPath & myFile)
DoEvents
wb.Sheets(1).Activate
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
DoEvents
wb.Sheets(1).Activate
ws.Copy
wb_name = ws.Name
ActiveWorkbook.SaveAs Filename:= _
Sheet1.Range("Savelocation").Value & wb_name & ".xlsx", FileFormat:=51
ActiveWorkbook.Close
Next ws
Application.DisplayAlerts = True
'Message Box when tasks are completed
MsgBox "Task Complete!"
End Sub