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

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
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,223,885
Messages
6,175,184
Members
452,615
Latest member
bogeys2birdies

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