View Single Post
 
Old 08-13-2021, 11:14 PM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,138
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

You can't make up your own syntax. The print to PDF does not support file naming from VBA.
You can save a contiguous range using ExportAsFixedFormat (For a single page enter e.g. 2-2 in the input box) e.g.
Code:
Sub SavePageRangeAsPDF()
Const sPath As String = "C:\Path\"
Dim sRange As String

    sRange = InputBox("Enter the range of pages to be printed eg 1-3")
    If sRange = "" Then
        MsgBox "No pages selected!", vbCritical, "Print Pages"
    End If

    ActiveDocument.ExportAsFixedFormat _
            OutputFileName:=sPath & "Robert.pdf", _
            ExportFormat:=wdExportFormatPDF, _
            Range:=wdExportFromTo, From:=Split(sRange, "-")(0), To:=Split(sRange, "-")(1)
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote