Printing multiple worksheets to separate xlsx or csv files

blkane

New Member
Joined
Nov 18, 2011
Messages
47
Hi, Several years ago, this forum helped me create a VB macro to print multiple worksheets to separate PDF's. The code is below. Now, I need to change the code so that it prints to either a separate CSV or XLSX file. Either is fine. I've played around with it but I'm not having any luck. I'm hoping someone can help.

Sub SaveWorksheetsAsPDFs()
Dim sFile As String
Dim sPath As String
Dim wks As Worksheet
With ActiveWorkbook
sPath = .Path& "\2016 10 Invoice Copies"
IfLen(Dir(sPath)) = 0 Then MkDir sPath 'folder doesn't already exist

For Each wksIn .Worksheets
If Not wks.Name Like "*DoNotPrint*" Then 'don't print datasheets
sFile = Format(WorksheetFunction.EoMonth(Now(), -1), "MM YYYY ")& wks.Name & ".pdf"
wks.ExportAsFixedFormat Type:=xlTypePDF, _
Filename:=sPath & sFile, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=False, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False
End If
Next wks
End With
End Sub

Thank you
Brenda
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college

Forum statistics

Threads
1,214,800
Messages
6,121,641
Members
449,044
Latest member
hherna01

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