Why VBA macro does not export document to PDF with correct page size?

56 views Asked by At

I need to export a four-page Publisher document into PDF format so that the first exported document contains pages 1-2 and the second exported document contains pages 3-4. I have prepared a macro to do this, but it saves the documents using the default paper page size (A4 size). In this case, the Publisher document is made in a custom size of 21 centimeters in width and 27 centimeters in height. It is nevertheless possible to export a file manually, but to do so, you must abandon the standardized page size in favor of the custom one. But how to make the macro do it?

Sub print_first_two_and_last_two_pages_separate_pdfs()

    ThisDocument.ExportAsFixedFormat Format:=pbFixedFormatTypePDF, Intent:=pbIntentPrinting, IncludeDocumentProperties:=False, DocStructureTags:=False, Filename:="1-2.pdf", From:=1, To:=2
    ThisDocument.ExportAsFixedFormat Format:=pbFixedFormatTypePDF, Intent:=pbIntentPrinting, IncludeDocumentProperties:=False, DocStructureTags:=False, Filename:="3-4.pdf", From:=3, To:=4

End Sub

Here is an example macro that should do what I need, but unfortunately it doesn't work:

Sub export_2_pdf_custom_size()
    ' Export the document to PDF with custom size
    With ActiveDocument
        .PageSetup.PageWidth = CentimetersToPoints(21)
        .PageSetup.PageHeight = CentimetersToPoints(27)
        .ExportAsFixedFormat Format:=pbFixedFormatTypePDF, Intent:=pbIntentPrinting, IncludeDocumentProperties:=False, DocStructureTags:=False, Filename:="1-2.pdf", From:=1, To:=2
    End With
End Sub

this is manual way to do that

0

There are 0 answers