saving as pdf with changing additional sheet name

spamiki

New Member
Joined
Apr 18, 2024
Messages
1
Office Version
  1. 365
Platform
  1. Windows
Hi,

I have a problem with VBA, I have a macro to save active excel sheet as PDF with custom name which is generated in cell.
Now I need to change it to have the same formula, but there have to additionally added to PDF additional excel sheet from the same file where sheet name will be generated in cell Z22 (in file there are 22 sheets, depend of chosed variant in active sheet, additional one generated in cell Z22 have to be also added and saved in one PDF)

Current code:

Sub ExportPDF()
With ActiveSheet
.ExportAsFixedFormat 0, Environ("USERPROFILE") & "\Desktop\" & _
.Range("B84").Value & ".pdf", OpenAfterPublish:=True
End With
End Sub

Guys, could you help me please?
Main active excel sheet named is "Report"

Thank you!
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Try this:
VBA Code:
Public Sub Save_2_Sheets_As_PDF()

    With ActiveSheet
        Worksheets(Array(.Name, .Range("Z22").Value)).Select
        .Activate
        .ExportAsFixedFormat Type:=xlTypePDF, Filename:=Environ("USERPROFILE") & "\Desktop\" & .Range("B84").Value & ".pdf", OpenAfterPublish:=True
        .Select
    End With
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,177
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