Need help to print Excel as PDF in a landscape Orientation and fit all columns on one page

Hi Team,

Can anyone suggest me a feasible way with UiPath to convert excel as PDF in a landscape orientation. Thanks!



Did you happen to try and use save excel as pdf activity?


Hi @divya.x.kuchi

Directly using UiPath Activities, not sure, but I did use this trick to get my workdone

Sub PrintDataSheets()
    Dim mySheets As Variant, sh

    mySheets = Array("InputData", "interMediateData", "OutputData")
    For Each sh In mySheets
        Sheets(sh).PageSetup.Orientation = xlLandscape

    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:="C:\Test" & ".pdf", _
        Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False
End Sub

You can use it in Invoke VBA

save this in a Macro.txt
and use it like this:

Same code is giving me as out of range error.

Looks like your code is to print multiple sheets in the same spreadsheet. Would it be possible to share the macro to print excel as PDF with options orientation - Landscape and Fit all columns in one page in one only sheet which don’t have the standard sheet name. Thanks!

I did. But it doesn’t have the option to change the orientation to landscape and fit all columns in one page


Can you please tey this…I hope you have only one sheet in your excel

Sub SaveAsPDF(output As String)
    Dim ws As Worksheet
    Set ws = ThisWorkbook.Sheets(1)
    ws.PageSetup.PrintArea = ws.UsedRange.Address
    ws.PageSetup.Orientation = xlLandscape
    ws.ExportAsFixedFormat Type:=xlTypePDF, Filename:=output, Quality:=xlQualityStandard, _
        IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
End Sub


Hi Anil,

It’s giving me an error


did you happen to send the output filelocation and filename as input?

send input like C:\Test.pdf