PDFing two tabs in one workbook in different formats

stroffso

Board Regular
Joined
Jul 12, 2016
Messages
160
Office Version
  1. 365
Platform
  1. Windows
Hi,

I have two tabs, one called Service and the other called Sub Service. The Service tab is in Portrait mode where as the Sub Service tab is in landscape mode.
What I want to do is is run some code that PDFs both files as they are into one document however whenever I do this it seems to only want to do it in one format, The code im using is below.

I can put them on the same tab if thats easier too but I just need from Rows 1-211 in portrait and Rows 211-225 in landscape, Any assistance greatly appreciated

VBA Code:
Sub BothpdfTest()
    Dim wb As Workbook
    Dim saveFolderPath As String
    Dim saveFileName As String
    
    ' Set a reference to the workbook
    Set wb = ThisWorkbook
    
    ' Prompt the user to choose the folder location using an Open dialog box
    With Application.FileDialog(msoFileDialogFolderPicker)
        .Title = "Select Folder to Save PDF"
        .Show
        If .SelectedItems.Count <> 0 Then
            saveFolderPath = .SelectedItems(1) & "\"
        Else
            Exit Sub
        End If
    End With
    
    ' Set the desired file name for the PDF file
    saveFileName = "Services 2024 " & Sheets("Service").Range("C3").Value & ".pdf"
    
    ' Select the specified tabs
    Sheets(Array("Service", "Sub Service ")).Select
    
    ' Export the selected tabs as a PDF file
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
                                   Filename:=saveFolderPath & saveFileName, _
                                   Quality:=xlQualityStandard, _
                                   IncludeDocProperties:=True, _
                                   IgnorePrintAreas:=False
    
    MsgBox "PDF file created successfully!", vbInformation
End Sub

thank you
 

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
Try inserting these lines before Sheets(Array("Service", "Sub Service ")).Select

VBA Code:
    Worksheets("Service").PageSetup.Orientation = xlPortrait
    Worksheets("Sub Service ").PageSetup.Orientation = xlLandscape
 
Upvote 0
Solution
Try inserting these lines before Sheets(Array("Service", "Sub Service ")).Select

VBA Code:
    Worksheets("Service").PageSetup.Orientation = xlPortrait
    Worksheets("Sub Service ").PageSetup.Orientation = xlLandscape
Of all the things I tried I didnt try that, amazing, thank you
 
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