Save Sheet As File (with Sheet name)

hansgrandia

Board Regular
Joined
Jan 10, 2015
Messages
53
Hello,

I'm trying to copy every sheet in workbook as separate file (on X drive) with the name of the sheet with below standing code. It now creates a single file with the name %20&%20ws.name%20&%20 including all sheets. What goes wrong here?

Thank you, Hans Grandia (Netherlands)

Code:
Sub SaveAsFile()

Application.ScreenUpdating = False
Dim ws As Worksheet
'eerste sheet selecteren
Worksheets(1).Activate
For Each ws In Worksheets
ws.Activate
With ActiveSheet
     .SaveAs Filename:="X: & ws.name & .xlsx", FileFormat:=xlWorkbookDefault
     .Close SaveChanges:=False
End With
Next
End Sub
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Code:
[color=darkblue]Sub[/color] SaveAsFile()
    [color=darkblue]Dim[/color] ws [color=darkblue]As[/color] Worksheet
    [color=green]'eerste sheet selecteren[/color]
    [color=green]'Worksheets(1).Activate[/color]
    Application.ScreenUpdating = [color=darkblue]False[/color]
    [color=darkblue]For[/color] [color=darkblue]Each[/color] ws [color=darkblue]In[/color] ThisWorkbook.Worksheets
        ws.Copy [color=green]'Copy the sheet as a seperate workbook[/color]
        ActiveWorkbook.SaveAs Filename:="X:\" & ws.Name & ".xlsx", FileFormat:=51
        ActiveWorkbook.Close SaveChanges:=[color=darkblue]False[/color]
    [color=darkblue]Next[/color]
    Application.ScreenUpdating = [color=darkblue]True[/color]
[color=darkblue]End[/color] [color=darkblue]Sub[/color]
 
Upvote 0

Forum statistics

Threads
1,223,231
Messages
6,170,884
Members
452,364
Latest member
springate

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