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

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
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,223,896
Messages
6,175,259
Members
452,626
Latest member
huntinghunter

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