Consulting

Results 1 to 4 of 4

Thread: Word document how to save 2 pages in 1 pdf file in a folder

  1. #1
    VBAX Regular
    Joined
    Oct 2018
    Location
    Antwerp
    Posts
    41
    Location

    Word document how to save 2 pages in 1 pdf file in a folder

    If I want to print the current page in a WORD document, ad PDF file and save it to the folder c:\folder\, the macro that works fine is easy to program (see under).
    Now I want to print 2 pages, the page where my cursor is in the word document + the following page.
    So these two pages have to be saved as pdf file.
    How do I do this?
    Thanks. (Edward).

    Sub print_this_page_to_pdf_in_folder()
    Dim sName As String
    Dim sPath As String
    With ActiveDocument
    sName = Left(.Name, InStr(.Name, ".") - 1)
    sName = sName & ".pdf"
    sPath = "C:\folder"

    .ExportAsFixedFormat _
    OutputFileName:=sPath & sName, _
    ExportFormat:=wdExportFormatPDF, _
    Range:=wdPrintCurrentPage
    End With
    End Sub

  2. #2
    The following, based on your original parameters will do that

    Dim sName As String
    Dim sPath As String
    Dim i As Long
        i = Selection.Information(wdActiveEndPageNumber)
        With ActiveDocument
            sName = Left(.Name, InStr(.Name, ".") - 1)
            sName = sName & ".pdf"
            sPath = "C:\folder\"
            MsgBox sPath & sName
            ActiveDocument.ExportAsFixedFormat OutputFileName:=sPath & sName, _
                                               ExportFormat:=wdExportFormatPDF, _
                                               OpenAfterExport:=False, _
                                               OptimizeFor:=wdExportOptimizeForPrint, _
                                               Range:=wdExportFromTo, From:=i, To:=i + 1
    
        End With
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  3. #3
    VBAX Regular
    Joined
    Oct 2018
    Location
    Antwerp
    Posts
    41
    Location
    Works great! This rocks (again).
    Thanks.
    .
    To finetune the macro:
    .
    Can the PDF file be named before saving?
    .

  4. #4
    The macro creates a PDF named from the document (as in your original), so it would have to be saved first. The alternative is to supply the macro with a name for the PDF.
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •