Save As XLSX not XLS

struf

Board Regular
Joined
Jul 2, 2002
Messages
107
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
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Try

Rich (BB code):
sFilename = sPath & ActiveSheet.Name & ".xlsx"

'copy the active sheet into new workbook
ActiveSheet.Copy
ActiveWorkbook.SaveAs _
Filename:=sFilename, _
FileFormat:=51, _
Password:="", _
CreateBackup:=False
 
Upvote 0

Forum statistics

Threads
1,224,566
Messages
6,179,558
Members
452,928
Latest member
101blockchains

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top