Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 07-19-2022, 07:21 AM
Bunndahabhain Bunndahabhain is offline Splitting a word document using VBA Windows 10 Splitting a word document using VBA Office 2019
Novice
Splitting a word document using VBA
 
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
 

Tags
splitting



Similar Threads
Thread Thread Starter Forum Replies Last Post
Splitting a word document using VBA Splitting merged Word document into individual .pdf documents (naming from a field in the file) ScarlettNZ Mail Merge 1 05-30-2019 12:53 AM
Splitting a word document using VBA Filename after splitting document Julian Word VBA 5 12-08-2015 04:51 AM
Splitting Word Document based on line content TwiceOver Word VBA 23 10-12-2015 02:01 PM
Document splitting MsLavigne Word 2 05-09-2012 05:52 AM
Splitting a word document using VBA WORD 2003 Need help splitting a HUGE Document dlawson Word 4 04-14-2009 12:22 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:46 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft