View Single Post
 
Old 07-19-2022, 07:21 AM
Bunndahabhain Bunndahabhain is offline Windows 10 Office 2019
Novice
 
Join Date: Jul 2022
Posts: 1
Bunndahabhain is on a distinguished road
Default Splitting a word document using VBA

I've found this code online that allows me to split each page into PDF and save it. However, I need to change it so that it splits every 2 pages. So each PDF document will have 2 pages. So the first document will have pages 1 and 2. The second document will have 3 and 4, and so on.

Here's the code I have so far.

Code:
Sub SaveAsSeparatePDFs()
'UpdatebyExtendoffice20181120
    Dim I As Long
    Dim xDlg As FileDialog
    Dim xFolder As Variant
    Dim xStart, xEnd As Integer
    On Error GoTo lbl
    Set xDlg = Application.FileDialog(msoFileDialogFolderPicker)
    If xDlg.Show <> -1 Then Exit Sub
    xFolder = xDlg.SelectedItems(1)
    xStart = CInt(InputBox("Start Page", "KuTools for Word"))
    xEnd = CInt(InputBox("End Page:", "KuTools for Word"))
    If xStart <= xEnd Then
        For I = xStart To xEnd
            ActiveDocument.ExportAsFixedFormat OutputFileName:= _
                xFolder & "\Page_" & I & ".pdf", ExportFormat:=wdExportFormatPDF, _
                OpenAfterExport:=False, OptimizeFor:=wdExportOptimizeForPrint, Range:= _
                wdExportFromTo, From:=I, To:=I, Item:=wdExportDocumentContent, _
                IncludeDocProps:=False, KeepIRM:=False, CreateBookmarks:= _
                wdExportCreateHeadingBookmarks, DocStructureTags:=True, _
                BitmapMissingFonts:=False, UseISO19005_1:=False
        Next
    End If
    Exit Sub
lbl:
    MsgBox "Enter right page number", vbInformation, "KuTools for Word"
End Sub



Many thanks for all your help in advance <3

Last edited by macropod; 07-19-2022 at 07:38 AM. Reason: Added code tags
Reply With Quote