#1
|
|||
|
|||
Split Word into pdf every X pages
Hi!
I have the below code that splits a word into individual pdfs by each page, creating a folder and dropping the file in there. The thing is that I would like to be able to select every X amount of pages instead of being one pdf per page. Any suggestions? Code:
Sub Merge_To_Individual_Files() ' Sourced from: https://www.msofficeforums.com/mail-...ps-tricks.html Application.ScreenUpdating = False Dim StrFolder As String, StrName As String, MainDoc As Document, i As Long, j As Long Const StrNoChr As String = """*./\:?|" Set MainDoc = ActiveDocument With MainDoc StrFolder = .Path & "\" With .MailMerge .Destination = wdSendToNewDocument .SuppressBlankLines = True On Error Resume Next For i = 1 To .DataSource.RecordCount With .DataSource .FirstRecord = i .LastRecord = i .ActiveRecord = i If Trim(.DataFields("X")) = "" Then Exit For 'StrFolder = .DataFields("Folder") & "" StrName = .DataFields("X") & "_" & .DataFields("X") End With On Error GoTo NextRecord .Execute Pause:=False For j = 1 To Len(StrNoChr) StrName = Replace(StrName, Mid(StrNoChr, j, 1), "_") Next StrName = Trim(StrName) StrFolderRowName = StrFolder & StrName If Dir(StrFolderRowName, vbDirectory) = "" Then MkDir StrFolderRowName With ActiveDocument 'Add the name to the footer '.Sections(1).Footers(wdHeaderFooterPrimary).Range.InsertBefore StrName '.SaveAs FileName:=StrFolder & StrName & ".docx", FileFormat:=wdFormatXMLDocument, AddToRecentFiles:=False ' and/or: .SaveAs FileName:=StrFolderRowName & "" & StrName & ".pdf", FileFormat:=wdFormatPDF, AddToRecentFiles:=False .Close SaveChanges:=False End With NextRecord: Next i End With End With Application.ScreenUpdating = True End Sub Last edited by macropod; 01-16-2022 at 01:41 PM. Reason: Added code tags |
#2
|
||||
|
||||
The code you posted does not split a Word document "into individual pdfs by each page". It processes a mailmerge creating a new file for each record. The number of pages for each record depends entirely on what's in the mailmerge main document, be that one page or one hundred.
The code for splitting a document is found under the Split Merged Output to Separate Documents topic in the same Mailmerge Tips & Tricks 'Sticky' thread you got your posted code from: https://www.msofficeforums.com/mail-...ps-tricks.html. That code allows you to specify how many pages each new document should contain.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
Oh, my bad. Thought it did something completely different. I just tested what you said and it actually does what I needed.
Thanks!! Quote:
|
Tags |
pdf conversion, vba code, word macro |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Split a Word document in "n" pages | dlinto | Word VBA | 1 | 03-24-2021 02:57 PM |
Why won't table split across pages? | lynn0712 | Word Tables | 5 | 12-16-2019 02:10 PM |
Split pages rom A3 to A4 | dominbdg | Word | 1 | 07-22-2019 08:36 AM |
workseet with Tables for VLOOKUP formulas needs to be split into 3 pages | innkeeper9 | Excel | 4 | 10-05-2016 01:45 PM |
Automatically split Mail Merge based on number of pages | SaneMan | Mail Merge | 1 | 12-03-2011 01:11 AM |