'How to set the PrintArea property of the PageSetup class?

I'm trying to print an area of a page to pdf.

I select the range but when I try to set the print area I get:

Run-time error '1004':
Unable to set the print area property of the PageSetup class

Sub printpdftest()

    Application.PrintCommunication = False
    Application.Goto Reference:="'9. Requerimientos Custodia'!R6C1"
    Dim myPath As String, myFile As String
    myPath = ThisWorkbook.Path & "\"
    firstDate = Format(Date, "ddmmyyyy")
    myFile = Format(Date, "ddmmyy") & " 9.RC" & ".PDF"    
    Application.Goto Reference:="R6C1"
    Selection.End(xlToRight).Select
    ActiveCell.Offset(25, 0).Select

    ActiveSheet.PageSetup.PrintArea = Range(Selection, "A1").Select   

    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=myFile, Quality:=xlQualityStandard, IncludeDocProperties:=False, IgnorePrintAreas:=False, OpenAfterPublish:=True

End Sub


Solution 1:[1]

the PrintArea function is supposed to get a string as an input

so had to change: ActiveSheet.PageSetup.PrintArea = Range(Selection, "A1").Select

for ActiveSheet.PageSetup.PrintArea = Range(Selection, "A1").Address

THX @RORY FOR THE SOLUTION

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Juan Lantigua