Log in

View Full Version : [SOLVED:] Turning one Word document into several PDF's



MartinDK
10-03-2019, 07:21 AM
Hello,

I've been recommended this forum from a friend of mine.

I need help finding the easiest way to convert a 15 page long Word document into several smaller PDF's, like this:
- Page 2, save as "Page 2.pdf"
- Page 3, save as "Page 3.pdf"
- Page 4, save as "Page 4.pdf"
- Page 5, save as "Page 5.pdf"
- Page 6-7, save as "Page 6-7.pdf"
- Page 8-10, save as "Page 8-10.pdf"
- Page 11, save as "Page 11.pdf"
- Page 12, save as "Page 12.pdf"
- Page 13, save as "Page 13.pdf"
- Page 14, save as "Page 14.pdf"

My current solution is to use a PDF-printer and manually 'printing' the pages and naming the files, but I'm certain there's a smarter and better way to do it. The task admittedly only takes a few minutes, but it's very repetitive and I know from experience that I'll end up making mistakes in the long run - I do this one or two times a month to make flyers for a free course that helps children cope with dyslexia in school.

I've automated a handful of functions already (it merges dates for meetings, locations, etc. from an excel file), but how to do this currently eludes me. I've considered turning it into subdocuments, but I'd really like to find a way to turn it straight into PDF's and saves them in a separate folder in the same place as the Word file, hopefully with just a few clicks of a button if at all possible to reduce the margin for errors.

I like to think that I know a lot of the basic functions in Word, but I've only dabbled with VBA a few times in the long distant past (and as I recall that didn't end well for me).

Help and advice is greatly appreciated, and I'll of course happily answer any clarifying questions you might have.

Kind regards,
Martin

macropod
10-03-2019, 11:25 PM
If the document you're trying to split is the result of a mailmerge, see:
• Split Merged Output to Separate Documents; and
• Send Mailmerge Output to Individual Files,
in the Mailmerge Tips and Tricks thread at:
http://www.msofficeforums.com/mail-merge/21803-mailmerge-tips-tricks.html

MartinDK
10-04-2019, 02:08 AM
Thank you kindly for the link Paul, there's a lot of interesting features in that comprehensive guide you've made for mailmerge that I'm going to experiment with in the future! Very interesting read that deserves kudos and a spot amongst my bookmarks.

I've closely read the two sections you directed me to, but I'm not sure they solves my dilemma. My 15 page long Word document is how it looks before I use the Mailmerge. We have a lot of different flyers, invitations to meetings, etc. that relies on the same dates/times. Before I got the document some poor person had to manually and painstakingly change all the dates in the ten different documents every time there was a change - which predictably resulted in frequent errors.

So I compiled the ten different files into one long document and ran it through mailmerge so we only have to type the data into a spreadsheet once, and then the mailmerge ensure that all the dates and times are fixed on every page automatically (of course it also means that if we do make a mistake it happens every document, but it's also a lot easier to spot).

Once I run a mailmerge I used a PDF printer and send first page 2, then page 3, ...., page 6-7, etc. to the PDF printer and name them manually. It solved our issue with posters/invitations saying contradictory dates and times, but if I accidentally type the wrong page number things start getting messy quick. As I understand the two sections you linked to, they would work if I used mailmerge the traditional way, with one document that merges information into several individual documents. I've been a bit creative and used mailmerge to ensure that all the individual information we have is merged into one document.

I hope the above makes sense to you - again, thank you so much for your time and interest!

gmayor
10-04-2019, 04:42 AM
The following should produce the required PDFs from your 14 page document. If it is 15 pages as in your later post, change the two references that refer to 14 to 15.


Sub PrintCustomPDF()
'Graham Mayor - https://www.gmayor.com - Last updated - 04 Oct 2019
Dim i As Long
Dim strName As String
Const strPath As String = "C:\Path\" 'the path to save the files
For i = 1 To 14
Select Case i
Case 1 To 5, 11 To 14
strName = "Page " & i & ".pdf"
SelectPages i, i
Case 6
strName = "Pages 6-7" & ".pdf"
SelectPages i, i + 1
Case 8
strName = "Pages 8-10" & ".pdf"
SelectPages i, i + 2
Case Else
GoTo Skip
End Select
Selection.ExportAsFixedFormat _
OutputFileName:=strPath & strName, _
ExportFormat:=wdExportFormatPDF, _
OpenAfterExport:=False, _
OptimizeFor:=wdExportOptimizeForPrint, _
ExportCurrentPage:=False, _
Item:=wdExportDocumentContent, _
IncludeDocProps:=True, _
KeepIRM:=True, _
CreateBookmarks:=wdExportCreateNoBookmarks, _
DocStructureTags:=True, _
BitmapMissingFonts:=True, _
UseISO19005_1:=True
ChangeFileOpenDirectory "D:\My Documents\Test\Merge\TestMerge\"
Skip:
Next i
End Sub


Private Sub SelectPages(lngStartPage As Long, lngEndPage As Long)
'Graham Mayor - https://www.gmayor.com - Last updated - 04 Oct 2019
Dim oRng As Range
Selection.GoTo What:=wdGoToPage, which:=wdGoToNext, Name:=lngStartPage
ActiveDocument.Bookmarks("\page").Range.Select
Set oRng = Selection.Range
If lngEndPage > lngStartPage Then
Selection.GoTo What:=wdGoToPage, which:=wdGoToNext, Name:=lngEndPage
ActiveDocument.Bookmarks("\page").Range.Select
oRng.End = Selection.End - 1
End If
Do While oRng.Characters.Last = Chr(13)
oRng.End = oRng.End - 1
Loop
oRng.Select
End Sub

MartinDK
10-05-2019, 12:02 AM
I think that did the trick! We got a lot of the graphic on the page which looks very weird when PDF'ed this way (I think it's due to the transparency setting on some of the graphics, at least that's what seems to be affected), but that's exactly the kind of function I was looking for :) thank you so much Graham. Now I just need to find out why the graphics get weird when I PDF through this code, but not when I do it regularly.

The document is 15 pages long, but currently I'm not printing the 1st or 15th page as they're being used to guide the user through the manual step by step process (in case someone else has to take over from me, I'd like it to be easy for them so they don't have to start from scratch like I did), and the last page is for reminders of things we need to improve or add to our flyvers.

I genuinely appreciate all the work and help, I'll be looking more into tinkering with the your code Graham to find out how it works, and hopefully finding tutorials on this forum for VBA.

Thank you for the excellent help and advice from both of you and Paul, it's greatly appreciated.