When running the below macro, ( it splits out a workbook's tabs into separate workbooks) it always saves as an *.xls file. I have been playing with it for a few days off and on, and can not seem to have it save as an *.xlsx
Any suggestions would be appreciated.
Public Sub Split_It()
Dim iWorksheet As Integer 'loop variable
Dim sFilename As String, sPath As String
sPath = GetFolder()
If Len(sPath) = 0 Then Exit Sub
sPath = sPath & "\"
On Error Resume Next
'loop through all worksheets
For iWorksheet = 1 To ActiveWorkbook.Worksheets.Count
Worksheets(iWorksheet).Activate
'set the filename for the output file
sFilename = sPath & ActiveSheet.Name
'copy the active sheet into new workbook
ActiveSheet.Copy
ActiveWorkbook.SaveAs _
Filename:=sFilename, _
FileFormat:=xlNormal, _
Password:="", _
CreateBackup:=False
ActiveWorkbook.Close
Next iWorksheet
End Sub
Function GetFolder() As String
Dim dlg As FileDialog
Set dlg = Application.FileDialog(msoFileDialogFolderPicker)
dlg.InitialFileName = "C:\Test\"
If dlg.Show = -1 Then
GetFolder = dlg.SelectedItems(1)
End If
End Function
Any suggestions would be appreciated.
Public Sub Split_It()
Dim iWorksheet As Integer 'loop variable
Dim sFilename As String, sPath As String
sPath = GetFolder()
If Len(sPath) = 0 Then Exit Sub
sPath = sPath & "\"
On Error Resume Next
'loop through all worksheets
For iWorksheet = 1 To ActiveWorkbook.Worksheets.Count
Worksheets(iWorksheet).Activate
'set the filename for the output file
sFilename = sPath & ActiveSheet.Name
'copy the active sheet into new workbook
ActiveSheet.Copy
ActiveWorkbook.SaveAs _
Filename:=sFilename, _
FileFormat:=xlNormal, _
Password:="", _
CreateBackup:=False
ActiveWorkbook.Close
Next iWorksheet
End Sub
Function GetFolder() As String
Dim dlg As FileDialog
Set dlg = Application.FileDialog(msoFileDialogFolderPicker)
dlg.InitialFileName = "C:\Test\"
If dlg.Show = -1 Then
GetFolder = dlg.SelectedItems(1)
End If
End Function