banner



How To Open 2 Pdfs In Separate Windows

Catechumen your Word Mail Merge into split up PDF documents! No third-political party plug-in, no complication, and no need to go moving and renaming documents.

Introduction

You lot would remember that converting a mail merge to carve up PDF documents would be like shooting fish in a barrel. However, a quick search gives up solutions which are either ridiculously complex or require a third-political party plug-in (ofttimes paid for). Worst of all, even if you become that to piece of work you will end up with a folder containing a load of files named something completely useless like document one, certificate 2, document 159. Yous will then spend a twenty-four hour period renaming files before yous can email them out or file them away.

And so we avoid all those problems and requite you a ane-push button solution which handles the whole thing, saving your PDF files with the names y'all want and in the folders you want (you can even have dissimilar folders for unlike files).

This is done using a Discussion Macro, the text of which is below. Read on, or watch the video, to find out how to add together the macro to Discussion, prepare upward your mail merge and then sit dorsum as the computer does the work for you.

The Video

The Super Quick Version

  • Copy the text of the Macro from beneath and add to Word.
  • Add the following fields to your Mail Merge information: DocFolderPath, DocFileName, PdfFolderPath, PdfFileName.
  • In the FileName fields, put the file names yous want for the separated Word Docs and converted PDFs. No need to include the extensions.
  • In the FolderPath fields put valid folder paths (e.yard. C:\Users\me\Documents). These tin be the same for all rows, or dissimilar – the choice is yours.
  • Create your Mail Merge.
  • Run the Macro
  • Sit back and let the computer work.

The Macro

******     UPDATE! – Windows code updated from what is shown in the video     ******

******     UPDATE! – Mac code now added     ******

Code for Windows

                                  Sub MailMergeToPdfBasic()                                                        ' Mark the start of the Subroutine (i.e. Macro) and name it "MailMergeToPdf"  ' Macro created by Imnoss Ltd  ' Please share freely while retaining attribution  ' Last Updated 2021-05-03      Dim masterDoc As Document, singleDoc As Document, lastRecordNum As Long   ' Create variables ("Post-it Notes") for later use      Set masterDoc = ActiveDocument                                               ' Identify the ActiveDocument (foremost doc when Macro run) as "masterDoc"            masterDoc.MailMerge.DataSource.ActiveRecord = wdLastRecord                   ' jump to the last active record (active = ticked in edit recipients)      lastRecordNum = masterDoc.MailMerge.DataSource.ActiveRecord                  ' retrieve the record number of the last active record so we know when to stop            masterDoc.MailMerge.DataSource.ActiveRecord = wdFirstRecord                  ' jump to the first active record (active = ticked in edit recipients)      Do While lastRecordNum > 0                                                   ' create a loop, lastRecordNum is used to end the loop by setting to zero (see below)          masterDoc.MailMerge.Destination = wdSendToNewDocument                    ' Identify that we are creating a word docx (and no e.g. an email)          masterDoc.MailMerge.DataSource.FirstRecord = masterDoc.MailMerge.DataSource.ActiveRecord              ' Limit the selection to just one document by setting the start ...          masterDoc.MailMerge.DataSource.LastRecord = masterDoc.MailMerge.DataSource.ActiveRecord               ' ... and end points to the active record          masterDoc.MailMerge.Execute False                                        ' run the MailMerge based on the above settings (i.e. for one record)          Set singleDoc = ActiveDocument                                           ' Identify the ActiveDocument (foremost doc after running the MailMerge) as "singleDoc"          singleDoc.SaveAs2 _              FileName:=masterDoc.MailMerge.DataSource.DataFields("DocFolderPath").Value & Application.PathSeparator & _                  masterDoc.MailMerge.DataSource.DataFields("DocFileName").Value & ".docx", _              FileFormat:=wdFormatXMLDocument                                      ' Save "singleDoc" as a word docx with the details provided in the DocFolderPath and DocFileName fields in the MailMerge data          singleDoc.ExportAsFixedFormat _              OutputFileName:=masterDoc.MailMerge.DataSource.DataFields("PdfFolderPath").Value & Application.PathSeparator & _                  masterDoc.MailMerge.DataSource.DataFields("PdfFileName").Value & ".pdf", _              ExportFormat:=wdExportFormatPDF                                      ' Export "singleDoc" as a PDF with the details provided in the PdfFolderPath and PdfFileName fields in the MailMerge data          singleDoc.Close False                                                    ' Close "singleDoc", the variable "singleDoc" can now be used for the next record when created          If masterDoc.MailMerge.DataSource.ActiveRecord >= lastRecordNum So     ' test if we have simply created a document for the terminal record              lastRecordNum = 0                                                    ' if and then nosotros set lastRecordNum to zero to point that the loop should cease          Else              masterDoc.MailMerge.DataSource.ActiveRecord = wdNextRecord           ' otherwise go to the side by side agile record          Stop If            Loop                                                                         ' loop dorsum to the Do showtime  End Sub                                                                          ' Mark the stop of the Subroutine                                                  

Code for Mac

                                  Sub MailMergeToPdf()                                                        ' Mark the start of the Subroutine (i.e. Macro) and name it "MailMergeToPdf"      Dim masterDoc As Certificate, recordNum As Long, singleDoc As Document  ' Create variables ("Postal service-it Notes") for afterwards use      Prepare masterDoc = ActiveDocument                                          ' Place the ActiveDocument (foremost physician when Macro run) as "masterDoc"            masterDoc.MailMerge.DataSource.ActiveRecord = wdLastRecord            For recordNum = 1 To masterDoc.MailMerge.DataSource.ActiveRecord         ' Set "recordNum" to 1 and start loop | second part defines end point for loop          masterDoc.MailMerge.DataSource.ActiveRecord = recordNum             ' Change the active tape in the MailMerge to the "recordNum"          masterDoc.MailMerge.Destination = wdSendToNewDocument               ' Identify that we are creating a word docx (and no eastward.g. an email)          masterDoc.MailMerge.DataSource.FirstRecord = recordNum              ' Limit the selection to just i document by setting the offset ...          masterDoc.MailMerge.DataSource.LastRecord = recordNum               ' ... and end points to the same number (which is the aforementioned as the active record)          masterDoc.MailMerge.Execute False                                   ' run the MailMerge based on the above settings (i.e. for one record)          Set singleDoc = ActiveDocument                                      ' Place the ActiveDocument (foremost medico after running the MailMerge) as "singleDoc"          singleDoc.SaveAs _              FileName:=masterDoc.MailMerge.DataSource.DataFields("DocFolderPath").Value & "/" & _                  masterDoc.MailMerge.DataSource.DataFields("DocFileName").Value & ".docx", _              fileFormat:=wdFormatXMLDocument                                 ' Save "singleDoc" equally a discussion docx with the details provided in the DocFolderPath and DocFileName fields in the MailMerge data          singleDoc.SaveAs _              FileName:=masterDoc.MailMerge.DataSource.DataFields("PdfFolderPath").Value & "/" & _                  masterDoc.MailMerge.DataSource.DataFields("PdfFileName").Value & ".pdf", _              fileFormat:=wdFormatPDF                                              ' Export "singleDoc" as a PDF with the details provided in the PdfFolderPath and PdfFileName fields in the MailMerge data          singleDoc.Close False                                               ' Shut "singleDoc", the variable "singleDoc" tin at present be used for the adjacent record when created      Next recordNum                                                          ' Add 1 to "recordNum" and return to the kickoff of the loop (line nether "For recordNum = 1 ..."  End Sub                                                                     ' Marking the end of the Subroutine                                                  

The Long Version

Calculation the Macro

To add a macro to Word y'all will need to be able to come across the Developer tab. If you lot don't have this appearing, that's perfectly normal for Word, they hide it past default. To go far appear is yous simply right-click anywhere in the ribbon and select "Customise the Ribbon". In the dialogue box which appears make certain the checkbox next to Programmer in the right-hand column is checked. Once done press Ok, and the Developer tab will appear in the Ribbon. This contains the Visual Bones and Macro buttons on the left-hand side.

Click the Visual Basic push in the Programmer tab to open up the Visual Bones editor where we will add together our macro. If you lot exercise not encounter a window called "Projection" and so click on the View menu and select "Projection Explorer". This will bring upwardly the Project window. In this window right-click on "Normal" and in the contextual card select "Insert" and then "Module". A new file called "Module1" will appear in the Modules folder under "Normal" (the file may have a different number if Module1 already exists).

The middle of the window will be a white sheet – this is the editing infinite for the new module. Copy the Macro from this article and paste it into the middle of the VBA editor.

Preparing the Data

Start by preparing your data exactly every bit y'all would for a normal mail merge – i.e. a sail in Excel with headers in the first row and information underneath.

For the macro to work, you will need to add in four extra columns named: DocFolderPath, DocFileName, PdfFolderPath, and PdfFileName. These should be exactly as written here, with no spaces and each word capitalised.

The fields DocFolderPath and PdfFolderPath should comprise paths to folders which exist on your system. If yous have a suitable folder open you tin can click in the address bar and copy the folder path from there. The binder paths may exist the aforementioned or dissimilar for different rows. If you wish, you can generate folder paths using formulas. You will need to make sure that each binder exists for the macro to work.

The fields DocFileName and PdfFileName should contain a name for the Discussion doc and PDF file respectively. If the files are all going into the same folder, the names need to exist unique to avoid overwriting. These can be created past copying and pasting eastward.g. a name, or generated by a formula as shown in the images. At that place is no need to add an extension (.docx or .pdf).

Word requires that a Word document be saved before converting to PDF so we have to salve the Discussion documents, even if you don't desire them.

Preparing the Postal service Merge Template

Prepare your post merge template as you would any other postal service merge. The iv extra fields tin be ignored unless yous want them to appear in the mail merge (I guess yous might want the file proper noun to appear in the header).

Set up your mail service merge template in Word as for a normal mail service merge - there is no need to add the extra fields anywhere

Running the Mail Merge to PDF

In the Programmer tab click the "Macros" button. Select the macro "MailMergeToPdf" and click Run.

Sit down back and let the magic happen.

We employ cookies on our website to give y'all the nigh relevant experience by remembering your preferences and repeat visits. By clicking "Have", you consent to the use of ALL the cookies.

Source: https://imnoss.com/word-mail-merge-to-separate-pdfs/

Posted by: philipstheares.blogspot.com

0 Response to "How To Open 2 Pdfs In Separate Windows"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel