Marco Code Error - Why is this extra blank white page added to my PDF? RRS feed

  • Question

  • Sub merge1record_at_a_time() '

    ' merge1record_at_a_time Macro



        Dim fd As FileDialog

        'Create a FileDialog object as a Folder Picker dialog box.

        Set fd = Application.FileDialog(msoFileDialogFolderPicker)

        With fd

            'Use the Show method to display the Folder Picker dialog box and return the user's action.

            'The user pressed the button.

            If .Show = -1 Then

                    For Each vrtSelectedItem In .SelectedItems

                    'vrtSelectedItem is aString that contains the path of each selected item.

                    'You can use any file I/O functions that you want to work with this path.

                    'This example displays the path in a message box.

            SelectedPath = vrtSelectedItem

            Next vrtSelectedItem


            MsgBox ("No Directory Selected.  Exiting")

            Exit Sub

            End If

        End With

        'Set the object variable to Nothing.

        Set fd = Nothing

    Application.ScreenUpdating = False

    MainDoc = ActiveDocument.Name

        ChangeFileOpenDirectory SelectedPath

        For i = 1 To ActiveDocument.MailMerge.DataSource.RecordCount

            With ActiveDocument.MailMerge

                .Destination = wdSendToNewDocument

                .SuppressBlankLines = True

                With .DataSource

                    .FirstRecord = i

                    .LastRecord = i

                    .ActiveRecord = i

                    docName = .DataFields("File").Value & ".pdf"      ' ADDED CODE

                End With

                .Execute Pause:=False

        Application.ScreenUpdating = False


            End With

            ActiveDocument.ExportAsFixedFormat OutputFileName:=docName, _

            ExportFormat:=wdExportFormatPDF, OpenAfterExport:=False, OptimizeFor:= _

            wdExportOptimizeForPrint, Range:=wdExportAllDocument, From:=1, To:=1, _

            Item:=wdExportDocumentContent, IncludeDocProps:=True, KeepIRM:=True, _

            CreateBookmarks:=wdExportCreateNoBookmarks, DocStructureTags:=True, _

            BitmapMissingFonts:=True, UseISO19005_1:=False


        ActiveDocument.Close (False)


        Next i

    Application.ScreenUpdating = True

    End Sub

    Tuesday, November 12, 2019 8:24 PM

All replies

  • Hi,

    Considering the issue is mainly related to VBA, to help you resolve the issue better, I will move the thread to Word for Developers. You may get more helpful replies there. Thanks for your kind understanding. 

    The reason why we recommend posting appropriately is you will get the most qualified pool of respondents, and other partners who read the forums regularly can either share their knowledge or learn from your interaction with us. Thank you for your understanding.

    Best Regards,


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnsf@microsoft.com.

    Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Office 2019.

    Wednesday, November 13, 2019 5:22 AM
  • Thanks Emily! I check for replies there
    Wednesday, November 13, 2019 8:03 PM