VBA Save Worksheets to PDF

Oprichnick

Board Regular
Joined
May 30, 2013
Messages
69
Hello,

I've been working in a piece of code that changes, in another workbook, the name of each tab according to cell values and saves each worksheet as pdf file.

It does change correctly the tabs name and saves them as PDF, also correctly (named according to each tab name).
However the info in the pdf is from the workbook in which I have the code.

Code:
Dim wks As Worksheet    Dim wks As Worksheet
    Dim strPath As String
    Dim folderpath As String  

    With Workbooks("DLQ.xls")
        For Each wks In .Sheets
            With wks
                If .Range("E16").Value <> "" Then .Name = Left(.Range("E16").Value, 3)
            End With
        Next wks
    End With



With Workbooks("X.xls")        For Each wks In .Sheets
            With wks
                ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
                "C:\Users\pedro.david\Desktop\Driscoll's\9. DLQ Report\" & wks.Name & ".pdf" _
                , Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
                :=False, OpenAfterPublish:=False
            End With
        Next wks
    End With

End Sub

Thanks,
Oprichnick
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Delete the ActiveSheet reference, so it becomes:
Code:
                .ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
                "C:\Users\pedro.david\Desktop\Driscoll's\9. DLQ Report\" & .Name & ".pdf" _
                , Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
                :=False, OpenAfterPublish:=False
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,175
Members
453,021
Latest member
Justyna P

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