sheets to PDF

STEEL010

Board Regular
Joined
Dec 29, 2017
Messages
76
Hi there,

I have a VBA code to split sheets, but now I want to save them as PDF.
And there for I have a code but do not know how to add to the code to the VBA code.
Can some help, I'm lost.....

Split code:
Private Sub CommandButton1_Click()
Dim Cl As Range
Dim ws As Worksheet
Dim Ky As Variant

Application.ScreenUpdating = False
Set ws = Sheets("OSAP Orders")
With CreateObject("scripting.dictionary")
For Each Cl In ws.Range("D2", ws.Range("D" & Rows.Count).End(xlUp).Offset(-1))
If Not .Exists(Cl.Value) And Cl.Value <> "" Then .Add Cl.Value, Nothing
Next Cl
For Each Ky In .Keys
ws.Range("A1").AutoFilter 4, Ky
Sheets.Add(, ws).Name = Ky
ws.AutoFilter.Range.EntireRow.Copy Sheets(Ky).Range("A1")
Sheets(Ky).Columns.AutoFit
Next Ky
End With
ws.AutoFilterMode = True
ws.Activate
End Sub

safe to PDF code:
'save splitted files to PDF
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
Filename:="C:\Documents" & Format(Now(), "yyyy-mm-dd") & " " & Cell.Value & ".pdf", _
OpenAfterPublish:=False


Greetings,
Steel010
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
.
This will save all sheets except OSAP Orders in the same folder as the workbook. You can edit the code
to further adhere to your requirements.

Code:
Option Explicit


Sub ExportToPDFs()
Dim nm As String
Dim ws As Worksheet
Dim saveInFolder As String
    
    saveInFolder = ThisWorkbook.Path
    If Right(saveInFolder, 1) <> "\" Then saveInFolder = saveInFolder & "\"
    


    For Each ws In Worksheets
       
            If Not (ws.Name Like "OSAP Orders") Then
                
                    ws.Select
                    nm = ws.Name
            
                    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
                    Filename:=saveInFolder & nm & ".pdf", _
                    Quality:=xlQualityStandard, IncludeDocProperties:=True, _
                    IgnorePrintAreas:=False, OpenAfterPublish:=False
            End If
        
    Next ws
        
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,230
Messages
6,170,883
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